# DO Statement

Statement: Marks the beginning of a DO construct. The DO construct controls the repeated execution of a block of statements or constructs. This repeated execution is called a loop.

A DO construct takes one of the following forms:

Block Form:

[name:] DO [label[, ] ] [loop-control]

block

[label] term-stmt

Non-block Form:

DO label [,] [loop-control]

block

[label] ex-term-stmt

name | (Optional) Is the name of the DO construct.
label | (Optional) Is a statement label identifying the terminal statement.
loop-control | Is one of the following: a loop iteration (see Iteration Loop Control) WHILE (see the DO WHILE statement) CONCURRENT (see the DO CONCURRENT statement)
block | Is a sequence of zero or more statements or constructs that make up the DO range.
term-stmt | Is the terminal statement for the block form of the construct.
ex-term-stmt | Is the terminal statement for the non-block form of the construct.

## Description

The terminal statement (term-stmt) for a block DO construct is 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.

The terminal statement (ex-term-stmt) for a non-block DO construct is an executable statement (or construct) that is identified by the label specified in the non-block DO statement. A non-block DO construct can share a terminal statement with another non-block DO construct. A block DO construct cannot share a terminal statement.

The following cannot be terminal statements for non-block DO constructs:

- CONTINUE (allowed if it is a shared terminal statement)

- CYCLE

- END (for a program or subprogram)

- EXIT

- GO TO (unconditional or assigned)

- Arithmetic IF

- RETURN

- STOP

The non-block DO construct is a deleted feature in the Fortran Standard. Intel® Fortran fully supports features deleted in the Fortran Standard.

The labeled form of a DO loop is an obsolescent feature in the Fortran Standard.

## Example

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)

The following two program fragments are also examples of DO statements:

      C   Initialize the even elements of a 20-element real array
          DIMENSION array(20)
          DO j = 2, 20, 2
            array(j) = 12.0
          END DO
      C
      C   Perform a function 11 times
          DO k = -30, -60, -3
            int = j / 3
            isb = -9 - k
            array(isb) = MyFunc (int)
          END DO

The following shows the final value of a DO variable (in this case 11):

        DO j = 1, 10
          WRITE (*, '(I5)') j
        END DO
        WRITE (*, '(I5)') j

Parent topic: C to D

## See Also

CONTINUE
CYCLE
EXIT
DO WHILE
DO CONCURRENT
Execution Control