XL Fortran for AIX 8.1

Language Reference

CASE

Purpose

The CASE statement initiates a CASE statement block in a CASE construct, which has a concise syntax for selecting, at most, one of a number of statement blocks for execution.

Format



>>-CASE--case_selector--+---------------------+----------------><
                        '-case_construct_name-'
 
 

case_selector



>>-+-DEFAULT------------------------------------------+--------><
   |    .-,--------------------------------------.    |
   |    V                                        |    |
   '-(----+-case_value-------------------------+-+--)-'
          +-low_case_value--:--high_case_value-+
          +-low_case_value--:------------------+
          '-:--high_case_value-----------------'
 
 

case_construct_name
Is a name that identifies the CASE construct.

case_value
is a scalar initialization expression of type integer, character, or logical

low_case_value, high_case_value
are each scalar initialization expressions of type integer, character, or logical

Rules

The case index, determined by the SELECT CASE statement, is compared to each case_selector in a CASE statement. When a match occurs, the stmt_block associated with that CASE statement is executed. If no match occurs, no stmt_block is executed. No two case value ranges can overlap.

A match is determined as follows:

case_value

DATA TYPE: integer, character or logical
MATCH for integer and character: case index = case_value
MATCH for logical: case index .EQV. case_value is true

low_case_value : high_case_value

DATA TYPE: integer or character
MATCH: low_case_value <= case index <= high_case_value

low_case_value :

DATA TYPE: integer or character
MATCH: low_case_value <= case index

: high_case_value

DATA TYPE: integer or character
MATCH: case index <= high_case_value

DEFAULT

DATA TYPE: not applicable
MATCH: if no other match occurs.

There must be only one match. If there is a match, the statement block associated with the matched case_selector is executed, completing execution of the case construct. If there is no match, execution of the case construct is complete.

If the case_construct_name is specified, it must match the name specified on the SELECT CASE and END SELECT statements.

DEFAULT is the default case_selector. Only one of the CASE statements may have DEFAULT as the case_selector.

Each case value must be of the same data type as the case_expr, as defined in the SELECT CASE statement. If any typeless constants or BYTE named constants are encountered in the case_selectors, they are converted to the data type of the case_expr.

When the case_expr and the case values are of type character, they can have different lengths. If you specify the -qctyplss compiler option, a character constant expression used as the case_expr remains as type character. The character constant expression will not be treated as a typeless constant.

Examples

ZERO: SELECT CASE(N)
 
  CASE DEFAULT ZERO          ! Default CASE statement for
                             ! CASE construct ZERO
       OTHER: SELECT CASE(N)
          CASE(:-1)          ! CASE statement for CASE
                             ! construct OTHER
             SIGNUM = -1
          CASE(1:) OTHER
              SIGNUM = 1
       END SELECT OTHER
  CASE (0)
    SIGNUM = 0
 
END SELECT ZERO

Related Information


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]