SELECT CASE

Purpose

The SELECT CASE statement is the first statement of a CASE construct. It provides a concise syntax for selecting, at most, one of a number of statement blocks for execution.

Syntax

Read syntax diagramSkip visual syntax diagram>>-+------------------------+--SELECT CASE--(--case_expr--)----><
   '-case_construct_name--:-'
 

case_construct_name
is a name that identifies the CASE construct
case_expr
is a scalar expression of type integer, character or logical

Rules

When a SELECT CASE statement is executed, the case_expr is evaluated. The resulting value is called the case index, which is used for evaluating control flow within the case construct.

If the case_construct_name is specified, it must appear on the END CASE statement and optionally on any CASE statements within the construct.

IBM Extension

The case_expr must not be a typeless constant or a BYTE data object.

End of IBM Extension

Examples

      ZERO: SELECT CASE(N)         ! start of CASE construct ZERO

        CASE DEFAULT ZERO
             OTHER: SELECT CASE(N) ! start of CASE construct OTHER
                CASE(:-1)
                   SIGNUM = -1
                CASE(1:) OTHER
                    SIGNUM = 1
             END SELECT OTHER
        CASE (0)
          SIGNUM = 0

      END SELECT ZERO

Related information