IF construct

The IF construct selects no more than one of its statement blocks for execution.

Read syntax diagramSkip visual syntax diagram>>-Block_IF_statement------------------------------------------><
 
Read syntax diagramSkip visual syntax diagram>>-statement_block---------------------------------------------><
 
Read syntax diagramSkip visual syntax diagram>>-+-------------------+---------------------------------------><
   | .---------------. |
   | V               | |
   '---ELSE_IF_block-+-'
 
Read syntax diagramSkip visual syntax diagram>>-+------------+----------------------------------------------><
   '-ELSE_block-'
 
Read syntax diagramSkip visual syntax diagram>>-END_IF_statement--------------------------------------------><
 
Block_IF_statement
See IF (block) for syntax details.
END_IF_statement
See END (Construct) for syntax details.

ELSE_IF_block

Read syntax diagramSkip visual syntax diagram>>-ELSE_IF_statement-------------------------------------------><
 
Read syntax diagramSkip visual syntax diagram>>-statement_block---------------------------------------------><
 
ELSE_IF_statement
See ELSE IF for syntax details.

ELSE_block

Read syntax diagramSkip visual syntax diagram>>-ELSE_statement----------------------------------------------><
 
Read syntax diagramSkip visual syntax diagram>>-statement_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 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.

Example

! 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