HP Fortran Programmer's Reference (September 2007)

HP Fortran statements
CASE
Chapter 10294
low
: For integer and character types, a match occurs if
c
.GE.
low
.
:
high
For integer and character types, a match occurs if
c
.LE.
high
.
low
:
high
For integer and character types, a match occurs if
c
.GE.
low
.AND.
c
.LE.
high
.
DEFAULT For integer, character, and logical types, a match occurs if no match is found
with any other
case-selector
and DEFAULT is specified as a
case-selector
.
If CASE DEFAULT is not present and no match is found with any of the other CASE statements,
none of the statement blocks within the CASE construct executes and execution resumes with
the first executable statement following the END SELECT statement.
At most only one DEFAULT selector can appear within a CASE construct.
Each CASE statement must specify a unique value or range of values within a particular CASE
construct. Only one match can occur, and only one statement block can execute.
All
case-selectors
and the case index within a particular CASE construct must be of the
same type: integer, character, or logical. However, the lengths of character types can differ.
The colon forms—
low
:, :
high
, or
low
:
high
—are not permitted for a logical type.
Although putting the CASE statements in order according to range may improve readability, it
is not necessary for correct or optimal execution of the CASE construct. In particular, DEFAULT
can appear anywhere among the CASE statements and need not be the last.
CASE statements inside a named CASE construct need not specify
construct-name
; but if they
do, the name they specify must match that of the SELECT CASE.
A CASE statement can have an empty statement block.
Examples
The following example considers a person’s credits and debits and prints a message indicating
whether a resulting account balance will be overdrawn, empty, uncomfortably small, or
sufficient:
INTEGER :: credits, debits
SELECT CASE (credits - debits)
CASE (:-1)
PRINT *, 'OVERDRAWN'
CALL TRANSFERFUNDS
CASE (0)
PRINT *, 'NO MONEY LEFT'
CASE (1:50)
PRINT *, 'BALANCE LOW'