HP Fortran Programmer's Reference (September 2007)

Execution control
Control constructs and statement blocks
Chapter 6 141
Example
The following CASE construct prints an error message according to the value of ios_err:
INTEGER :: ios_err
...
SELECT CASE (ios_err)
CASE (:900)
PRINT *, ”Unknown error”
CASE (913)
PRINT *, ”Out of free space”
CASE (963:971)
PRINT *, ”Format error”
CASE (1100:)
PRINT *, ”ISAM error”
CASE DEFAULT
PRINT *, ”Miscellaneous Error”
END SELECT
DO construct
The DO construct repeatedly executes a statement block. The syntax of the DO statement
provides two ways to specify the number of times the statement block executes:
By specifying a loop count.
By testing a logical expression as a condition for executing each iteration.
You can also omit all control logic from the DO statement, in effect creating an infinite loop.
The following sections describe the three variations of the DO construct.
You can use the CYCLE and EXIT statements to alter the execution logic of the DO construct.
For information about these statements, see “Flow control statements” on page 146.
Counter-controlled DO loop
A counter-controlled DO loop uses an index variable to determine the number of times the loop
executes.
Syntax
[
construct-name
: ] DO
index
=
init
,
limit
[ ,
step
]
statement-block
END DO [
construct-name
]
HP Fortran also supports the older, FORTRAN 77-style syntax of the DO loop:
DO
label index
=
init
,
limit
[ ,
step
]
statement-sequence
label terminal-statement