SELECT CASE                                                     Statement

SELECT CASE testexpression

                [CASE expressionlistA

                                [statementsA]]

                [CASE expressionlistB

                                [statementsB]]

                [CASE expressionlistC

                                [statementsC]]...

                [CASE ELSE

                                [elsestatements]]

END SELECT

Description

SELECT CASE evaluates a test expression, to conditionally execute one of several groups of statements. An expressionlistN component is required for every optional CASE clause inside of SELECT CASE. The optional component, statementsN is the group of statements to be executed when testexpression matches any expression in a expressionlistN. Inside a CASE clause, statements are executed up to the next CASE clause or END SELECT; after all statements in a CASE clause are executed, execution continues with the next statement after END SELECT. If testexpression doesn't match any expression in any of the expressionlists and CASE ELSE is included, elsestatements are executed. If CASE ELSE is not included and testexpression doesn't match any expression in any of the expressionlists, execution continues with the next statement after END SELECT.

Example

REM SELECT CASE Example

'SELECT CASE performs conditional execution

CheckHat("Blue")

CheckHat("Orange")

SUB CheckHat(Hat)

  SELECT CASE Hat

  CASE "Blue"

    PRINT "Kyle's hat"

  CASE "Green"

    PRINT "Stan's hat"

  CASE "Cyan"

    PRINT "Eric's hat"

  CASE "Orange", "Hood"

    PRINT "Kenny's hat"

  CASE "White"

    PRINT "Chef's hat"

  CASE "Striped"

    PRINT "Mr. Hat"

  CASE "Christmas", "Santa"

    PRINT "Mr. Hankey's hat"

  CASE ELSE

    PRINT "Unknown Hat"

  END SELECT

END SUB

Output

Kyle's hat

Kenny's hat

Related Items

IF...THEN...ELSE