Switch

The Switch statement allows selection among multiple blocks of statements.

Syntax:

Switch expression

 case expression

  statements

  break

 case expression

  statements

 break

EndSwitch

Parameters:

(s) expression an expression that must evaluate to an integer.

 

The Switch statement allows selection among multiple blocks of statements, depending on the value of an expression. The expression must evaluate to an integer.

The Switch statement causes the statements in the switch body to be scanned by the parser as it attempts to find a case statement. When a case statement is found, the expression following the case statement is evaluated, and if the expression evaluates to the same value as the expression following the Switch statement, execution of the following statements is initiated. The EndSwitch statement terminates the Switch structure.

If a matching case expression was found, and execution was initiated, the following statements will affect continued execution:

Note: Switch and Select may be used interchangeably. They are synonyms for the same statement.

EndSwitch, EndSelect, "End Switch", and "End Select" may be used interchangeably.

 

Example:


response=AskLine("Switch", "Enter a number between one and three", 1, 0)
Switch response
   Case 1
      Message("Switch", "Case 1 entered")
      Break
   Case 2
      Message("Switch", "Case 2 entered")
      Break
   Case 3
      Message("Switch", "Case 3 entered")
      Break
   Case response ; default case
      Message("Switch", "Default case entered")
      Break
EndSwitch
See Also:

Select, If, For, GoSub, While