HP Fortran Programmer's Reference (September 2007)

HP Fortran statements
DO
Chapter 10 327
When
label
is present in the DO statement, it specifies the label of the terminating statement
of the DO loop. The terminating statement
cannot
be any of the following statements:
GO TO (unconditional)
GO TO (assigned)
IF (arithmetic)
IF (block)
ELSE or ELSE IF
END, END IF, END SELECT, or END WHERE
RETURN
STOP
•DO
Any nonexecutable statement
Note, however, that the terminating statement can be an IF (logical) or an END DO statement.
To maintain compatibility with some older versions of Fortran, you can use the +onetrip
compile-line option to ensure that every counter-controlled DO loop in the program executes at
least once.
Extended-range DO loops
Extended-range DO loops—a compatibility extension—allow a program to transfer control
outside the DO loop’s range and then back into the DO loop. Extended-range DO loops work as
follows: if a control statement inside a DO loop transfers control to a statement outside the DO
loop, then any subsequent statement can transfer control back into the body of the DO loop.
For example, in the following code, the range of the DO loop is extended to include the
statement GOTO 20, which transfers control back to the body of the DO loop:
DO 50 i = 1, 10
20 n = n + 1
IF (n > 10) GOTO 60
50 CONTINUE ! normally, the range ends here
60 n = n + 100 ! this is the extended range,
GOTO 20 ! which extends down to this line
Examples
The following DO construct displays the integers 1 through 10: