IF construct
The IF construct selects no more than one of its statement blocks for execution.
- Block_IF_statement
- See IF (block) for syntax details.
- END_IF_statement
- See END (Construct) for syntax details.
ELSE_IF_block
- ELSE_IF_statement
- See ELSE IF for syntax details.
ELSE_block
- ELSE_statement
- See ELSE for syntax details.
The scalar logical expressions in an IF construct
(that is, the block IF and ELSE
IF statements) are evaluated in the order of their appearance
until a true value, an ELSE statement, or
an END IF statement is found:
- If a true value or an ELSE statement is found, the statement block immediately following executes, and the IF construct is complete. The scalar logical expressions in any remaining ELSE IF statements or ELSE statements of the IF construct are not evaluated.
- If an END IF statement is found, no statement blocks execute, and the IF construct is complete.
If the IF construct name is specified, it must appear on the IF statement and END IF statement, and optionally on any ELSE IF or ELSE statements. You can branch to an END IF statement from only within its IF construct.
Examples
! Get a record (containing a command) from the terminal
DO
WHICHC: IF (CMD .EQ. 'RETRY') THEN ! named IF construct
IF (LIMIT .GT. FIVE) THEN ! nested IF construct
! Print retry limit exceeded
CALL STOP
ELSE
CALL RETRY
END IF
ELSE IF (CMD .EQ. 'STOP') THEN WHICHC ! ELSE IF blocks
CALL STOP
ELSE IF (CMD .EQ. 'ABORT') THEN
CALL ABORT
ELSE WHICHC ! ELSE block
! Print unrecognized command
END IF WHICHC
END DO
END



