1 IF Tests the value of an expression and, depending on the syntax specified, executes the following: o One command following the THEN keyword if the expression is true o Multiple commands following the $THEN command if the expression is true o One or more commands following the $ELSE command if the expression is false Format $ IF expression THEN [$] command or $ IF expression $ THEN [command] command . . . $ [ELSE] [command] command . . . $ ENDIF NOTE Compaq advises against assigning a symbolic name that is already a DCL command name. Compaq especially discourages the assignment of symbols such as IF, THEN, ELSE, and GOTO, which can affect the interpretation of command procedures. 2 Parameters expression Defines the test to be performed. The expression can consist of one or more numeric constants, string literals, symbolic names, or lexical functions separated by logical, arithmetic, or string operators. Expressions in IF commands are automatically evaluated during the execution of the command. Character strings beginning with alphabetic characters that are not enclosed in quotation marks (" ") are assumed to be symbol names or lexical functions. The command language interpreter (CLI) replaces these strings with their current values. Symbol substitution in expressions in IF commands is not iterative; that is, each symbol is replaced only once. However, if you want iterative substitution, precede a symbol name with an apostrophe (') or ampersand (&). The command interpreter does not execute an IF command when it contains an undefined symbol. Instead, the command interpreter issues a warning message and executes the next command in the procedure. For a summary of operators and details on how to specify expressions, see the OpenVMS User's Manual. command Specifies the DCL command or commands to be executed, depending on the syntax specified, when the result of the expression is true or false. 2 Examples 1.$ COUNT = 0 $ LOOP: $ COUNT = COUNT + 1 . . . $ IF COUNT .LE. 10 THEN GOTO LOOP $ EXIT This example shows how to establish a loop in a command procedure, using a symbol named COUNT and an IF statement. The IF statement checks the value of COUNT and performs an EXIT command when the value of COUNT is greater than 10. 2.$ IF P1 .EQS. "" THEN GOTO DEFAULT $ IF (P1 .EQS. "A") .OR. (P1 .EQS. "B") THEN GOTO 'P1' $ WRITE SYS$OUTPUT "Unrecognized parameter option ''P1' " $ EXIT $ A: ! Process option a . . . $ EXIT $ B: ! Process option b . . . $ EXIT $ DEFAULT: ! Default processing . . . $ EXIT This example shows a command procedure that tests whether a parameter was passed. The GOTO command passes control to the label specified as the parameter. If the procedure is executed with a parameter, the procedure uses that parameter to determine the label to branch to. For example: @TESTCOM A When the procedure executes, it determines that P1 is not null, and branches to the label A. Note that the EXIT command causes an exit from the procedure before the label B. 3.$ SET NOON . . . $ LINK CYGNUS,DRACO,SERVICE/LIBRARY $ IF $STATUS $ THEN $ RUN CYGNUS $ ELSE $ WRITE SYS$OUTPUT "LINK FAILED" $ ENDIF $ EXIT This command procedure uses the SET NOON command to disable error checking by the command procedure. After the LINK command, the IF command tests the value of the reserved global symbol $STATUS. If the value of $STATUS indicates that the LINK command succeeded, then the program CYGNUS is run. If the LINK command returns an error status value, the command procedure issues a message and exits.