5.4.1 Indexed DO Constructs

The indexed DO construct controls iterative processing (the statements in its range are repeatedly executed a specified number of times). It takes the following form:

[name:]
DO [s[,]] v = e1,e2[,e3]
   block
[s] term-stmt [name]
name (Alpha only)
Is the name of the DO construct.
s
Is the optional label of an executable statement. The executable statement must physically follow the DO construct in the same program unit.
v
Is a variable with an integer or real data type; v cannot be an array element or a record field.

This variable is the control variable for the loop.

e1, e2, e3
Are arithmetic expressions.

Variables e1, e2, and e3 are the initial, terminal, and increment parameters, respectively. If the increment parameter is omitted, the default value is 1.

block
Is a sequence of zero or more statements.
term-stmt
Is the terminal statement for the DO construct.

Rules and Behavior

If the 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.

On Alpha processors, 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 same construct name must not be used for different named constructs in the same program unit; it must be unique.

The following cannot be terminal statements for DO constructs.

The range of the DO statement includes all the statements that follow the DO statement, up to and including the terminal statement.

The DO construct first evaluates the expressions e1, e2, and e3 to determine values for the initial, terminal, and increment parameters, respectively. The increment parameter (e3) cannot be zero.

The value of the initial parameter e1 is assigned to the control variable v. If the data type of the initial, terminal, and increment parameters is not the same as the data type of the control variable, they are converted before they are used.

The following arithmetic expression shows the number of executions of the DO range (also called the iteration count):

    [(e2 - e1 + e3)/e3]

The notation [e] represents the largest integer whose magnitude does not exceed the magnitude of e and whose sign is the same as the sign of e.

If the iteration count is zero or negative, the body of the loop is not executed.

If you specify the compiler option NOF77 and the iteration count is zero or negative, the body of the loop executes once.


Previous Page Next Page Table of Contents