FORTRAN 77 Language Reference

## Description

The DO statement contains the following constructs.

### Labeled DO Loop

A labeled DO loop consists of the following:

• DO statement

• Set of executable statements called a block

• Terminal statement, usually a CONTINUE statement

### Terminal Statement

The statement identified by s is called the terminal statement. It must follow the DO statement in the sequence of statements within the same program unit as the DO statement.

The terminal statement should not be one of the following statements:

• Unconditional GO TO

• Assigned GO TO

• Arithmetic IF

• Block IF/ELSE IF

• ELSE

• END IF

• RETURN

• STOP

• END DO

If the terminal statement is a logical IF statement, it can contain any executable statement, except:

• DO/DO WHILE

• Block IF/ELSE IF

• ELSE IF

• ELSE

• END IF

• END

• Logical IF

### DO Loop Range

The range of a DO loop consists of all of the executable statements that appear following the DO statement, up to and including the terminal statement.

If a DO statement appears within the range of another DO loop, its range must be entirely contained within the range of the outer DO loop. More than one labeled DO loop can have the same terminal statement.

If a DO statement appears within an IF, ELSE IF, or ELSE block, the range of the associated DO loop must be contained entirely within that block.

If a block IF statement appears within the range of a DO loop, the corresponding END IF statement must also appear within the range of that DO loop.

### Block DO Loop @

A block DO loop consists of:

• DO statement

• Set of executable statements called a block

• Terminal statement, an END DO statement

This loop is nonstandard.

Execution proceeds as follows:

1. The expressions e1, e2, and e3 are evaluated. If e3 is not present, its value is assumed to be one.

2. The DO variable is initialized with the value of e1.

3. The iteration count is established as the value of the expression:

MAX (INT ((e2 - e1 + e3)/),e3 0)

The iteration count is zero if either of the following is true:

• e1 > e2 and e3 > zero.

• e1 < e2 and e3 < zero.

If the -onetrip compile time option is specified, then the iteration count is never less than one.

4. The iteration count is tested, and, if it is greater than zero, the range of the DO loop is executed.

### Terminal Statement Processing

After the terminal statement of a DO loop is executed, the following steps are performed:

1. The value of the DO variable, if any, is incremented by the value of e3 that was computed when the DO statement was executed.

2. The iteration count is decreased by one.

3. The iteration count is tested, and if it is greater than zero, the statements in the range of the DO loop are executed again.