|
|
(5 intermediate revisions by 3 users not shown) |
Line 1: |
Line 1: |
| Select Case ''testexpression'' <br /> | | Select Case ''testexpression'' <br /> |
| :::[Case ''expressionlistA'' <br />
| | :[Case ''expressionlistA'' <br /> |
| ::::::[''statementsA'']] <br />
| | ::[''statementsA'']] <br /> |
| :::[Case ''expressionlistB'' <br />
| | :[Case ''expressionlistB'' <br /> |
| ::::::[''statementsB'']] <br />
| | ::[''statementsB'']] <br /> |
| :::[Case ''expressionlistC'' <br />
| | :[Case ''expressionlistC'' <br /> |
| ::::::[''statementsC'']]... <br />
| | ::[''statementsC'']]... <br /> |
| :::[Case Else <br />
| | :[Case Else <br /> |
| ::::::[''elsestatements'']] <br />
| | ::[''elsestatements'']] <br /> |
| End Select | | End Select |
|
| |
|
Line 16: |
Line 16: |
| == Example == | | == Example == |
|
| |
|
| <pre> | | <tabber> |
| | JavaScript= |
| | <syntaxhighlight lang="JavaScript"> |
| | // Select Case Example |
| | /* Select Case performs conditional execution */ |
| | |
| | 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"); |
| | } |
| | } |
| | |
| | CheckHat("Blue"); |
| | CheckHat("Orange"); |
| | </syntaxhighlight> |
| | |-| |
| | BASIC= |
| | <syntaxhighlight lang="vb.net"> |
| Rem Select Case Example | | Rem Select Case Example |
| 'Select Case performs conditional execution | | 'Select Case performs conditional execution |
Line 41: |
Line 80: |
| End Select | | End Select |
| End Sub | | End Sub |
| </pre> | | </syntaxhighlight> |
| | </tabber> |
|
| |
|
| == Output == | | == Output == |
Line 55: |
Line 95: |
|
| |
|
| [[Category:Language Reference]] | | [[Category:Language Reference]] |
| | |
| | [[Category:Statements - Flow of control]] |
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
// Select Case Example
/* Select Case performs conditional execution */
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");
}
}
CheckHat("Blue");
CheckHat("Orange");
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