关键字参考


Switch...Case...EndSwitch

条件运行语句.

Switch <表达式>
    Case <值> [To <值>] [,<值> [To <值>] ...]
        语句1
        ...
    [Case <值> [To <值>] [,<值> [To <值>] ...]
        语句2
        ...]
    [Case Else
        语句N
        ...]
EndSwitch

参数

<表达式> 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 evaluted exactly once each time through the structure.
<值> To <值> The case is executed if the expression is between the two values.
<值> The case is executed if the expression matches the value.

注意/说明

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 condition, will be executed.

Switch 语句允许嵌套使用.Switch 语句对字符运算是大小写敏感的.

相关

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

示例/演示


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

MsgBox(0, Default, $msg)