Select Case

From NSB App Studio
Revision as of 22:08, 10 September 2012 by Admin (talk | contribs)
Jump to navigation Jump to search

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 an 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