Select Case: Difference between revisions
m Ghenne moved page Select case to Select Case |
|||
Line 14: | Line 14: | ||
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. | 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 == | == Example (Basic) == | ||
<pre> | <pre> | ||
Line 41: | Line 41: | ||
End Select | End Select | ||
End Sub | End Sub | ||
</pre> | |||
== Example (JavaScript) == | |||
<pre> | |||
// Select Case Example | |||
/* Select Case performs conditional execution */ | |||
CheckHat("Blue"); | |||
CheckHat("Orange"); | |||
function CheckHat(Hat) { | |||
switch (true) { | |||
case (Hat == "Blue"): | |||
NSB.Print("Kyle's hat"); | |||
break; | |||
case (Hat == "Green"): | |||
NSB.Print("Stan's hat"); | |||
break; | |||
case (Hat == "Cyan"): | |||
NSB.Print("Eric's hat"); | |||
break; | |||
case (Hat == "Orange"): case (Hat == "Hood"): | |||
NSB.Print("Kenny's hat"); | |||
break; | |||
case (Hat == "White"): | |||
NSB.Print("Chef's hat"); | |||
break; | |||
case (Hat == "Striped"): | |||
NSB.Print("Mr. Hat"); | |||
break; | |||
case (Hat == "Christmas"): case (Hat == "Santa"): | |||
NSB.Print("Mr. Hankey's hat"); | |||
break; | |||
default: | |||
NSB.Print("Unknown Hat"); | |||
} | |||
} | |||
</pre> | </pre> | ||
Revision as of 21:48, 19 May 2013
Select Case testexpression
- [Case expressionlistA
- [statementsA]]
- [statementsA]]
- [Case expressionlistB
- [statementsB]]
- [statementsB]]
- [Case expressionlistC
- [statementsC]]...
- [statementsC]]...
- [Case Else
- [elsestatements]]
- [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 (Basic)
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
Example (JavaScript)
// Select Case Example /* Select Case performs conditional execution */ CheckHat("Blue"); CheckHat("Orange"); function CheckHat(Hat) { switch (true) { case (Hat == "Blue"): NSB.Print("Kyle's hat"); break; case (Hat == "Green"): NSB.Print("Stan's hat"); break; case (Hat == "Cyan"): NSB.Print("Eric's hat"); break; case (Hat == "Orange"): case (Hat == "Hood"): NSB.Print("Kenny's hat"); break; case (Hat == "White"): NSB.Print("Chef's hat"); break; case (Hat == "Striped"): NSB.Print("Mr. Hat"); break; case (Hat == "Christmas"): case (Hat == "Santa"): NSB.Print("Mr. Hankey's hat"); break; default: NSB.Print("Unknown Hat"); } }
Output
Kyle's hat Kenny's hat