02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>HP</strong> <strong>Fortran</strong> statements<br />

CASE<br />

low: For integer and character types, a match occurs if c .GE. low.<br />

:high For integer and character types, a match occurs if c .LE. high.<br />

low : high For integer and character types, a match occurs if c .GE. low .AND. c .LE.<br />

high.<br />

DEFAULT For integer, character, and logical types, a match occurs if no match is found<br />

with any other case-selector and DEFAULT is specified as a<br />

case-selector.<br />

If CASE DEFAULT is not present and no match is found with any of the other CASE statements,<br />

none of the statement blocks within the CASE construct executes and execution resumes with<br />

the first executable statement following the END SELECT statement.<br />

At most only one DEFAULT selector can appear within a CASE construct.<br />

Each CASE statement must specify a unique value or range of values within a particular CASE<br />

construct. Only one match can occur, and only one statement block can execute.<br />

All case-selectors and the case index within a particular CASE construct must be of the<br />

same type: integer, character, or logical. However, the lengths of character types can differ.<br />

The colon forms—low:, :high, orlow:high—are not permitted for a logical type.<br />

Although putting the CASE statements in order according to range may improve readability, it<br />

is not necessary for correct or optimal execution of the CASE construct. In particular, DEFAULT<br />

can appear anywhere among the CASE statements and need not be the last.<br />

CASE statements inside a named CASE construct need not specify construct-name; butifthey<br />

do, the name they specify must match that of the SELECT CASE.<br />

A CASE statement can have an empty statement block.<br />

Examples<br />

The following example considers a person’s credits and debits and prints a message indicating<br />

whether a resulting account balance will be overdrawn, empty, uncomfortably small, or<br />

sufficient:<br />

INTEGER :: credits, debits<br />

SELECT CASE (credits - debits)<br />

CASE (:-1)<br />

PRINT *, 'OVERDRAWN'<br />

CALL TRANSFERFUNDS<br />

CASE (0)<br />

PRINT *, 'NO MONEY LEFT'<br />

CASE (1:50)<br />

PRINT *, 'BALANCE LOW'<br />

260<br />

Chapter 10

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!