SELECT CASE
(Statement)
Execute the statement block associated with the matching condition out of multiple conditions.
SELECT CASE <expression>
CASE <item>[,<item>...]
:
[CASE ELSE]
END SELECT
This statement evaluates <expression> and compares it with <item> of the first CASE statement. If a match is found, the statement block following the first CASE statement is executed. If the <item> of the first CASE statement does not match, comparisons are made with <item> of the subsequent CASE statement.
<expression> is an arithmetic expression or a character string.
<item> is a variable, a constant, an expression or a conditional expression. The conditional expression can be specified as follows.
-
<arithmetic expression 1> TO <arithmetic expression 2>This checks whether the result of <expression> is any value between <arithmetic expression 1> and <arithmetic expression 2>. The TO keyword cannot be used if <expression> is a character string.
-
IS <comparison operator> <arithmetic expression>This compares the result of <expression> with the value of <arithmetic expression>. If <expression> is a character string, <comparison operator> can be "=" only.
The CASE ELSE statement executes if <expression> does not match any of CASE statements.
CASE ELSE should precede END SELECT.
REM Evaluate more than one condition
SELECT CASE Index
|
'If the index value and the CASE statement value match,
'the command executes
|
CASE 0
|
'If the index is 0
|
STOP
|
'Stop program execution
|
CASE 1
|
'If the index is 1
|
HALT "STOP"
|
'Stop program execution
|
CASE 2
|
'If the index is 2
|
HOLD "STOP"
|
'Stop program execution temporarily
|
CASE 3
|
'If the index is 3
|
STOPEND
|
'Cycle-stop a continuously executed program
|
CASE 4
|
'If the index is 4
|
ON li1 + li2 GOSUB *samp1, *samp2, *samp3
|
|
|
'Call a subroutine beginning with the nth labelname
'depending upon the value n of li1+li2
|
CASE 5
|
'If the index is 5
|
ON li1 + li2 GOTO *samp1, *samp2, *samp3
|
|
|
'Jump to the nth label depending upon the value n of li1+li2
|
CASE 6 TO 8
|
'If the index is 6 to 8
|
PRINTDBG "Reservation"
|
|
'Output a message to the debug window
|
|
CASE IS ≥ 9
|
'If the index is 9 or greater
|
END
|
'Declare the end of motion executed by the program
|
END SELECT
|
'Declare the end of conditions evaluation statement
|