7.5.1 Forms for DO Constructs

A DO construct takes one of the following forms:

Block Form:

[name:] DO [label][,] [loop-control]
      block
[label] term-stmt

Nonblock Form:

DO label[,] [loop-control]

name
Is the name of the DO construct.

label
Is a statement label identifying the terminal statement.

loop-control
Is a DO iteration (see Section 7.5.2.1) or a (DO) WHILE statement (see Section 7.5.3).

block
Is a sequence of zero or more statements or constructs.

term-stmt
Is the terminal statement for the construct.

Rules and Behavior

A block DO construct is terminated by an END DO or CONTINUE statement. If the block DO statement contains a label, the terminal statement must be identified with the same label. If no label appears, the terminal statement must be an END DO statement.

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

A nonblock DO construct is terminated by an executable statement (or construct) that is identified by the label specified in the nonblock DO statement. A nonblock DO construct can share a terminal statement with another nonblock DO construct. A block DO construct cannot share a terminal statement.

The following cannot be terminal statements for nonblock DO constructs:

The nonblock DO construct is an obsolescent feature in Fortran 95 and Fortran 90.

Examples

The following example shows equivalent block DO and nonblock DO constructs:

   DO I = 1, N                ! Block DO
     TOTAL = TOTAL + B(I)
   END DO

   DO 20 I = 1, N             ! Nonblock DO
20 TOTAL = TOTAL + B(I)

The following example shows a simple block DO construct (contains no iteration count or DO WHILE statement):

DO
  READ *, N
  IF (N == 0) STOP
  CALL SUBN
END DO

The DO block executes repeatedly until the value of zero is read. Then the DO construct terminates.

The following example shows a named block DO construct:

LOOP_1: DO I = 1, N
          A(I) = C * B(I)
        END DO LOOP_1

The following example shows a nonblock DO construct with a shared terminal statement:

   DO 20 I = 1, N
   DO 20 J = 1 + I, N
20 RESULT(I,J) = 1.0 / REAL(I + J)

For More Information:

For details on obsolescent features in Fortran 95 and Fortran 90, see Appendix A.


Previous Page Next Page Table of Contents