switch <gen_value> { case <values>: <command_block> ... default: <command_block> }
Execute a command or block of commands on the result of a multi-way decision.
switch command:
<gen_value>
A generic value. This can be the value of one of the following types:
numeric, point, string, time, epointer, group, symbology (color, font etc.), window, channel, panel, menupane, treenode
Its type will be identified in context.
case statement:
<values>
One or more values
of the same type as <gen_value>
separated by commas. Arrays may be used in which case all elements are
tested individually for a match.
<command_block>
One or more
commands to be executed if the value of <gen_value>
matches any of <values>.
There can be as many case statements as necessary.
default statement:
<command_block>
One or more commands to be executed if the value of <gen_value>
does not match any of the <values>
in the preceding case statements.
If used, the default statement must follow the last case statement. The word other may be used as an alternative to default if preferred.
-u
Make string-matching case-sensitive. The default behavior is to ignore
case differences.
-w
Make string-matching treat the case <values>
as wild patterns. The default behavior is not to.
switch x { case 1: y=x; # Execute one command case 2: { y=x; z=x } # Execute a command block case 3: null; # No action case 4,5,6: x=25; # Multiple choice case xs[1:10]: x=35; # Choice from array range default: x=50; # Default action }
switch ss, -w { case 'a*': | ss begins with a case 'b*': | ss beigns with b default: !ss begins with neither a nor b }