5.4.2 DO WHILE Constructs

The DO WHILE construct is similar to the indexed DO construct. However, while the DO construct executes unconditionally for a fixed number of iterations, the DO WHILE construct executes conditionally for as long as a logical expression contained in it continues to be true. The DO WHILE construct takes the following form:

[name:] DO [s[,]] WHILE (e)
   block
[s] term-stmt [name]
name (Alpha only)
Is the name of the DO WHILE construct.
s
Is the label of an executable statement. The executable statement must physically follow the DO construct in the same program unit.
e
Is a logical expression.
block
Is a sequence of zero or more statements.
term-stmt
Is the terminal statement for the DO construct.

Rules and Behavior

The DO WHILE statement tests the logical expression at the beginning of each execution of the loop, including the first. If the value of the expression is true, the statements in the body of the loop are executed. If the expression is false, control transfers to the statement following the loop.

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

You can transfer control out of a DO WHILE construct, but not into it from elsewhere in the program.

Example

The following example shows a valid DO WHILE construct:

CHARACTER*132 LINE
I = 1
LINE(132:) = 'x'
DO WHILE (LINE(I:I) .EQ. ' ')
    I = I + 1
END DO


Previous Page Next Page Table of Contents