HP Fortran Programmer's Reference (September 2007)

Execution control
Control constructs and statement blocks
Chapter 6 143
END IF
END DO
END DO
The following example uses the older syntactic form. Note that, unlike the newer form,
old-style nested DO loops can share the same terminal statement:
DO 10 i = 1, 99
DO 10 j = i+1, 100
if (scores(i) <= scores(j)) GO TO 10
temp = scores(i)
scores(i) = scores(j)
scores(j) = temp
10 CONTINUE
Conditional DO loop
A conditional DO loop uses the WHILE syntax to test a logical expression as a condition for
executing the next iteration.
Syntax
[
construct-name
:] DO WHILE (
logical-expression
)
statement-block
END DO [
construct-name
]
Fortran 90 also supports the older syntax of the DO WHILE loop:
DO
label
WHILE (
logical-expression
)
statement-sequence
label terminal-statement
Execution logic
1. The loop becomes active.
2. The
logical-expression
is evaluated. If the result of the evaluation is false, the loop
becomes inactive, and the normal flow of execution resumes with the first executable
statement following the END DO statement, or in the old DO-loop syntax, the terminal
statement.
3.
statement-block
executes. (In the case of the old-style syntactic form, both
statement-sequence
and
terminal-statement
execute.)
4. Go to Step 2.
Example
! Compute the number of years it takes to double the value of an
! investment earning 4% interest per annum
REAL :: money, invest, interest
INTEGER :: years