5.7.3.3 Nested IF Constructs

You can include an IF construct in the statement block of another IF construct, if the nested IF construct is completely contained within a statement block. It cannot overlap statement blocks.

The following shows a nested IF construct:

  Form                     Example
  IF (expr) THEN           IF (A .LT. 100) THEN
    block1                   INRAN = INRAN + 1
    IF (expr2) THEN          IF (ABS(A-AVG) .LE. 5.) THEN
      block1a                  INAVG = INAVG + 1
    ELSE                     ELSE
      block1b                  OUTAVG = OUTAVG + 1
    END IF                   END IF
  ELSE                     ELSE
    block2                   OUTRAN = OUTRAN + 1
  END IF                   END IF

If A is less than 100, the code immediately after the IF is executed. This code contains a nested IF construct. If the absolute value of A minus AVG is less than or equal to 5, block1a is executed. If the absolute value of A minus AVG is greater than 5, block1b is executed.

If A is greater than or equal to 100, block2 is executed, and the nested IF construct (in block1) is not executed.


Previous Page Next Page Table of Contents