Select Case: Difference between revisions
No edit summary |
No edit summary |
||
Line 52: | Line 52: | ||
== Related Items == | == Related Items == | ||
[[if...then...else| | [[if...then...else|If...Then...Else]] | ||
[[Category:Language Reference]] | [[Category:Language Reference]] |
Revision as of 01:38, 24 August 2012
Select Case testexpression
- [Case expressionlistA
- [statementsA]]
- [statementsA]]
- [Case expressionlistB
- [statementsB]]
- [statementsB]]
- [Case expressionlistC
- [statementsC]]...
- [statementsC]]...
- [Case Else
- [elsestatements]]
- [elsestatements]]
- [Case expressionlistA
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 Selrct.
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