Control Structures

switch

Supported By

Syntax

switch expression
case expression
   statementList
case expression
   statementList
...
[default
   statementList]

end switch

Example

switch x
case 1
  put "x is 1"
case 2
  put "x is 2"
case 3
  put "x is 3"
default
  put "x is something else"
end switch

Description

The switch structure evaluates the specified expression and executes the series of statements underneath the corresponding case clause with the same value. If no corresponding case clause is found, the switch structure executes the series of statements underneath the default clause, if it exists.

See Also

if, if