Main sections
SELECT
SELECT n
CASE 3; ...
CASE >3; ...
CASE 2 TO 5; ...
DEFAULT; ...
ENDSELECT
The SELECT keyword starts a SELECT block of code. The SELECT block gives your code the ability to take different actions depending on the value of n.
Within the SELECT statement there are one or more CASE statements which compare n to a given value.
If the value of n meets the conditions of the particular CASE statement being evaluated, the code-block following that CASE statement will be run. If more than one CASE statement matches the requirements, only the first matching code-block will be executed.
DEFAULT (optional) is a special type of CASE statement. If none of the CASE statements match n then the code-block under the DEFAULT statement (if a DEFAULT case exists) will be run.
CASE statement examples
-CASE 3
'n' must be exactly 3
-CASE >3
'n' must be bigger than 3
-CASE 2 TO 5
'n' must be at least 2 and not more than 5
-DEFAULT
None of the statements above matched 'n'
Attention: The expression "n" is evaluated for each CASE call.
Example:
// SELECT CASE DEFAULT ENDSELECT
FOR n=0 TO 10
PRINT "n="+n, 100, 100
SELECT n
CASE 7
PRINT "n="+n+": CASE 7", 0, n*10
CASE >9
PRINT "n="+n+": CASE >9", 0, n*10
CASE >3
PRINT "n="+n+": CASE >3", 0, n*10
CASE 3 TO 8
PRINT "n="+n+": CASE 3 TO 8", 0, n*10
DEFAULT
PRINT "n="+n+": DEFAULT", 0, n*10
ENDSELECT
NEXT
SHOWSCREEN
MOUSEWAIT
Output:
n=0: DEFAULT
n=1: DEFAULT
n=2: DEFAULT
n=3: CASE 3 TO 8
n=4: CASE >3
n=5: CASE >3
n=6: CASE >3
n=7: CASE 7
n=8: CASE >3
n=9: CASE >3
n=10: CASE >9