# 7.5 DO Constructs

The DO construct controls the repeated execution of a block of statements or constructs. (This repeated execution is called a loop.)

The number of iterations of a loop can be specified in the initial DO statement in the construct, or the number of iterations can be left indefinite by a simple DO ("DO forever") construct or DO WHILE statement.

The EXIT and CYCLE statements modify the execution of a loop. An EXIT statement terminates execution of a loop, while a CYCLE statement terminates execution of the current iteration of a loop. For example:

    DO
      READ (EUNIT, IOSTAT=IOS) Y
      IF (IOS /= 0) EXIT
      IF (Y <0) cycle
      call sub_a(y)
    end do

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.

For More Information:

- On the CYCLE statement, see Section 7.5.4.
- On the EXIT statement, see Section 7.5.5.
- On DO loops in FORALL constructs, see Section 4.2.5.
- On the INDEPENDENT directive (which can make assertions about DO loops on Tru64 UNIX systems), see Section 15.3.4.

Previous Page Next Page Table of Contents