SELECT [CASE]
 
Syntax

SELECT [CASE] expression
[CASE expressionlist]
    [statements]
[CASE ELSE]
    [statements]
ENDSELECT
Description


Select case executes specific code depending on the value of an expression. If the expression matches the first case then it's code is executed otherwise the next cases are compared and if one case matches then its code is executed. If no cases are matched and there is a 'case else' on the end then it will be executed, otherwise the whole select case block will be skipped. 

Syntax of an expression list:
expression [{TO expression | relational operator expression}][, ...]

example of expression lists:
CASE "A"                       ' the "A" is equivalent to &H41,   multi-character strings can not be used in CASE statements
CASE 5 TO 10
CASE > "e"
CASE 1, 3 TO 10
CASE 1, 3, 5, 7, 9

The SELECT expression must be an INTEGER, and the CASE expressions must also be INTEGER.

You can exit a SELECT/ CASE with a GOTO or RETURN statement.

Example

PRINT "Choose a number between 1 and 10: "
DEBUGIN choice
SELECT choice
CASE 1
        PRINT "number is 1"
CASE 2
        PRINT "number is 2"
CASE 3, 4
        PRINT "number is 3 or 4"
CASE 5 TO 10
        PRINT "number is in the range of 5 to 10"

CASE <= 20
        PRINT "number is in the range of 11 to 20"

CASE ELSE
        PRINT "number is outside the 1-20 range"
ENDSELECT
Differences from other BASICs

See also