XL Fortran for AIX 8.1

Language Reference


IF Construct

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



>>-Block_IF_statement------------------------------------------><
 
 
>>-statement_block---------------------------------------------><
 
 
>>-+-------------------+---------------------------------------><
   | .---------------. |
   | V               | |
   '---ELSE_IF_block-+-'
 
 
>>-+------------+----------------------------------------------><
   '-ELSE_block-'
 
 
>>-END_IF_statement--------------------------------------------><
 
 

Block_IF_statement
See IF (Block) for syntax details.

END_IF_statement
See END (Construct) for syntax details.

ELSE_IF_block



>>-ELSE_IF_statement-------------------------------------------><
 
 
>>-statement_block---------------------------------------------><
 
 

ELSE_IF_statement
See ELSE IF for syntax details.

ELSE_block



>>-ELSE_statement----------------------------------------------><
 
 
>>-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


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]