HP Fortran Programmer's Reference (September 2007)

HP Fortran statements
DO
Chapter 10328
DO i = 1, 10
WRITE (*, *) i
END DO
The next example is a FORTRAN 77-style DO loop that does the same as the preceding
example:
DO 50 i = 1, 10
WRITE (*, *) i
50 CONTINUE
The following DO construct iterates 5 times, decrementing the loop index from 10 to 2:
DO i = 10, 1, -2
END DO
The following is an example of a DO WHILE loop:
DO WHILE (sum < 100.0)
sum = sum + get_num(unit)
END DO
The following example illustrates the use of the EXIT statement to exit from a nested DO loop.
The loops are named to control which loop is exited. Note that
loop-control
is missing from
both the inner and outer loops, which therefore can be exited only by means of one of the EXIT
statements:
outer:DO
READ *, val
new_val = 0
inner:DO
new_val = new_val + proc_val(val)
IF (new_val >= max_val) EXIT inner
IF (new_val == 0) EXIT outer
END DO inner
END DO outer
The next DO construct never executes:
DO i = 10, 1
END DO
Related statements
CONTINUE, CYCLE, END (construct), and EXIT
Related concepts
For related information, see the following:
“DO construct” on page 141