インテル® Fortran コンパイラー 19.0 デベロッパー・ガイドおよびリファレンス

DO WHILE

Statement: Executes the range of a DO construct while a specified condition remains true.

[name:] DO [label[, ]] WHILE (expr)

   block

[END DO [name]]

name

(Optional) Is the name of the DO WHILE construct.

label

(Optional) Is a label specifying an executable statement in the same program unit.

expr

Is a scalar logical (test) expression enclosed in parentheses.

block

Is a sequence of zero or more statements or constructs that make up the DO range.

Description

If a construct name is specified in a DO WHILE statement, the same name must appear in a terminal END DO statement. If no construct name is specified in the DO WHILE statement, no name can appear in the terminal END DO statement, if one is specified.

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 END DO is specified, it terminates the construct. If END DO is not specified, when all of the iterations have completed execution, the loop terminates, and the DO construct becomes inactive.

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.

Example

The following example shows a DO WHILE statement:

  CHARACTER*132 LINE
  ...
  I = 1
  DO WHILE (LINE(I:I) .EQ. ' ')
    I = I + 1
  END DO

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

The following shows another example:

  CHARACTER(1) input
  input = ' '
  DO WHILE ((input .NE. 'n') .AND. (input .NE. 'y'))
     WRITE (*, '(A)') 'Enter y or n: '
     READ (*, '(A)') input
  END DO

See Also