
Program Execution Controls |
Examples:
IF(A + 8)1010,1020,1030
SWITCH = A**2 - 8**2
IF (SWITCH) 100,200,300
4.1.5 Logical IF Statement
We have given several examples of logical IF statements already in this manual. In effect, if the logical expression evaluated is TRUE, a specified statement is executed next. If the logical expression is FALSE, execution continues with the statement following the logical IF statement.
The format of the logical IF statement is
IF (exp) stmt
where
exp is a logical expression
stmt is any executable statement except DO, a block IF, ELSE IF, ELSE, END IF, END, or other logical IF
A function reference in the controlling logical expression is permitted to affect parameters in the statement 'stmt.'
Examples:
IF (SWITCH .EO. 1) GO TO FINISH
IF (SWITCH .NE. 1) WRITE (6,20) TOTALS
LOGICAL DONE
DONE = (A * *2 .GT. 8**2)
IF (DONE) PAUSE
IF (.NOT. DONE) GO TO START
4.1.6 IF, ELSE IF, and ELSE Blocks
The block IF statement is used with the END IF statement and, optionally, the ELSE IF and ELSE statements to control program execution.
Together with other executable FORTRAN statements, they can form 'IF blocks,' 'ELSE IF blocks,' or 'ELSE blocks,' the first statements of which must be IF, ELSE IF, or ELSE, respectively.
These blocks may be 'nested.' For example, an IF block may contain another IF block, which may contain another IF block, etc. These blocks may also be empty. For example, there may be no executable statements at all between a block IF state- ment and its corresponding END IF statement.
An IF block consists of all the executable statements after the block IF statement up to, but not including, the next ELSE IF, ELSE, or END IF statement on the same nesting level as the block IF statement.
An ELSE IF block consists of all the executable statements after the ELSE IF state- ment up to, but not including, the nest ELSE IF, ELSE, or END IF statement that has the same nesting level as the ELSE IF statement.