HP Fortran Programmer's Reference (September 2007)

HP Fortran statements
DO
Chapter 10326
DO
Controls execution of DO loop.
Syntax
[
construct-name
:] DO [
label
] [
loop-control
]
construct-name
is the name given to the DO construct. If
construct-name
is specified, an
END DO statement must appear at the end of the DO construct and have the
same
construct-name
.
label
is the label of an executable statement that terminates the DO loop. If you
specify
label
, you can terminate the DO loop either with an END DO
statement or with an executable statement; the terminating statement
must include
label
. If you do not specify
label
, you must terminate the DO
loop with the END DO statement.
loop-control
is information used by the DO statement to control the loop. It can take one
of the following forms:
index
=
init
,
limit
[,
step
]
WHILE (
logical-expression
)
loop-control
is omitted
In the first form,
index
is a scalar variable of type integer or real;
init
,
limit
, and
step
are scalar expressions of type integer or real. In the second
form,
logical-expression
is a scalar logical expression. In the third form,
loop-control
is omitted. If you use the second or third form, you must
terminate the DO loop with the END DO statement.
Description
The syntax of the DO statement allows for the following types of DO loops:
Counter-controlled loop: a loop count is calculated that controls the number of times the
block is executed, unless a prior exit occurs. A loop variable is incremented or
decremented after each execution.
While loop: a condition (
logical-expression
) is tested before each execution of the
block; when it is false, execution ceases. An exit may occur at any time.
Infinite loop: there is no
loop-control
; repeated execution of the block ceases only when
an exit from the loop occurs.