Keyword Reference


Switch...Case...EndSwitch

Conditionally run statements.

Switch <expression>
Case <value> [To <value>] [,<value> [To <value>] ...]
statement1
...
[Case <value> [To <value>] [,<value> [To <value>] ...]
statement2
...]
[Case Else
statementN
...]
EndSwitch

Parameters

<expression> An expression that returns a value. The value from the expression is then compared against the values of each case until a match is found. This expression is always evaluated exactly once each time through the structure.
<value> To <value> The case is executed if the expression is between the two values.
<value> The case is executed if the expression matches the value.

Remarks

If no cases match the Switch value, then the Case Else section, if present, is executed. If no cases match and Case Else is not defined, then none of the code inside the Switch structure, other than the initial expression, will be executed.

Switch statements may be nested. Switch statements are case-insensitive.

Related

If...Then, If...Else...EndIf, Select...EndSelect, ContinueCase

Example

#include <MsgBoxConstants.au3>

Local $sMsg = ""

Switch @HOUR
        Case 6 To 11
                $sMsg = "Good Morning"
        Case 12 To 17
                $sMsg = "Good Afternoon"
        Case 18 To 21
                $sMsg = "Good Evening"
        Case Else
                $sMsg = "What are you still doing up?"
EndSwitch

MsgBox($MB_SYSTEMMODAL, "", $sMsg)