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-----------------' |
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:
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.
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