Skip to main content

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 compaired 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 wll 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" CASE 5 TO 10 CASE > "e" CASE 1, 3 TO 10 CASE 1, 3, 5, 7, 9

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

  • SELECT CASE is used in Visual BASIC
  • SELECT is used in PBASIC
  • either is allowed in ARMbasic
  • Visual BASIC uses an optional IS before relational operators
  • ENDSELECT is used to terminate the SELECT in both ARMbasic and PBASIC
  • END SELECT (seperate words) are used in Visual BASIC

See also