# 5.4 DO Constructs

A DO construct controls the repeated execution of a block of statements. (This repeated execution is called a loop.) DO constructs can be indexed or pretested and indefinite (DO WHILE).

If a DO or DO WHILE statement does not contain a terminal statement label, the construct must be terminated by an END DO statement. If it does contain a terminal statement label, the END DO is optional.

The following example shows mandatory and optional END DO statements:

      Mandatory                 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

On Alpha processors, a DO construct can have a symbolic name. If the construct is named, the name of the construct must also follow the terminating END DO statement.

On Alpha processors, an EXIT or CYCLE statement can be used to modify the execution of a DO loop. An EXIT statement terminates execution of the loop, while a CYCLE statement terminates execution of the current iteration of the loop. For example:

    DO

      READ (EUNIT, IOSTAT=IOS) Y

      IF (IOS .NE. = 0) EXIT

      IF (Y .LE. 0) CYCLE

      CALL SUB_A(Y)

    END DO

In this case, if an error or end-of-file occurs, the DO construct terminates. If a negative value for Y is read, the program skips to the next READ statement.

Previous Page Next Page Table of Contents