HP Fortran Programmer's Reference (September 2007)

Execution control
Control constructs and statement blocks
Chapter 6140
[
construct-name
:] SELECT CASE (
case-expr
)
[CASE (
case-selector
) [
construct-name
]
statement-block
]
...
[CASE DEFAULT [
construct-name
]
statement-block
]
END SELECT [
construct-name
]
Notes on syntax
case-selector
is one of the following:
case-value
low
:
:
high
low
:
high
case-selectors
must be mutually exclusive and must agree in type with
case-expr
.
case-expr
must evaluate to a scalar value and must be an integer, logical, or character type.
If
construct-name
is given in the SELECT CASE statement, the same name may appear after
any CASE statement within the construct, and must appear in the END CASE statement. The
construct name cannot be used as a name for any other entity within the program unit.
CASE constructs can be nested. Construct names can then be useful in avoiding confusion.
Although the Standard forbids branching to any statement in a CASE construct other than the
initial SELECT CASE statement from outside the construct, HP Fortran allows it. The
Standard allows branching to the END SELECT statement from within the construct.
Execution logic
The execution sequence of the CASE construct is as follows:
1.
case-expr
is evaluated.
2. The resulting value is compared to each
case-selector
.
3. If a match is found, the corresponding
statement-block
executes.
4. If no match is found but a CASE DEFAULT statement is present, its
statement-block
executes.
5. If no match is found and there is no CASE DEFAULT statement, execution of the CASE
construct terminates without any block executing.
6. The normal flow of execution resumes with the first executable statement following the
END SELECT statement, unless a statement in
statement-block
transfers control.