CASE |
![]() ![]() ![]() |
The CASE statement provides conditional execution dependant on the result of expression evaluation.
Format
BEGIN CASE CASE expr statement(s) CASE expr statement(s) END CASE
where
The expressions are evaluated in turn until one evaluates to true. The statements associated with that test expression are then executed and control passes to the statement following the END CASE. Only one of the statement groups is executed. If none of the test expressions evaluates to true, no statements are executed.
It is frequently useful to execute a default set of statements where no specific test expression results in non-zero result. This can be achieved by a case of the form CASE 1 which makes use of the fact that 1 is the value of the boolean True. This must be the final element of the CASE statement.
Example
N = DCOUNT(ITEMS, @VM) BEGIN CASE CASE N = 0 DISPLAY "There are no items" CASE N = 1 DISPLAY "There is 1 item" CASE 1 DISPLAY "There are " : N : " items" END CASE
This program fragment displays a message indicating the number of values in the ITEMS variable. Note the use of the CASE 1 construct. |