7.5.3 DO WHILE Statement

The DO WHILE statement executes the range of a DO construct while a specified condition remains true. The statement takes the following form:

 DO [label][,] WHILE (expr)
Is a label specifying an executable statement in the same program unit.
Is a scalar logical expression enclosed in parentheses.

Rules and Behavior

Before each execution of the DO range, the logical expression is evaluated. If it is true, the statements in the body of the loop are executed. If it is false, the DO construct terminates and control transfers to the statement following the loop.

If no label appears in a DO WHILE statement, the DO WHILE loop must be terminated with an END DO statement.

You can transfer control out of a DO WHILE loop but not into a loop from elsewhere in the program.


The following example shows a DO WHILE statement:

I = 1
  I = I + 1

The following examples show required and optional END DO statements:

Required                 Optional
DO WHILE (I .GT. J)         DO 10 WHILE (I .GT. J)
  ARRAY(I,J) = 1.0            ARRAY(I,J) = 1.0
  I = I - 1                   I = I - 1
END DO                   10 END DO

Previous Page Next Page Table of Contents