# switch Another flow control command
Usage
    switch(<expression>)
    {
        case(<value>)[:]<command>
        [break]
        case(<value>)[:]<command>
        [break]
        ....
        match(<wildcard_expression>)[:]<command>
        [break]
        ....
        regexp(<regular_expression>)[:]<command>
        [break]
        ....
        case(<value>)[:]<command>
        [break]
        ....
        default[:]<command>
        [break]
    }
Description
The switch command is based on the standard C 'switch' keyword. It executes conditionally groups of commands choosen from a larger set of command groups. First <expression> is evaluated (<expression> is any arithmetic or string expression). Then the 'match','regexp','case' and 'default' labels are evaluated sequentially in the order of appearance. case(<value>)[:]<command> The <value> is evaluated and is compared against the result of <expression>. The comparison is case insensitive (if the values are strings). If <value> is equal to <expression> then <command> is executed. Please note that <command> must be either a single instruction or an instruction block enclosed in braces. If <command> contains a break statement inside or if break is specified just after the <command> then the execution of the switch is terminated otherwise the nex label is evaluated. match(<value>)[:]<command> The <value> is expected to be a wildcard expression (containing '*' and '?' wildcards) that is matched against <expression>. If there is a match (a complete case insensitive match!) then the related <command> is executed. brea is treated just like in the case label. regexp(<value>)[:]<command> The <value> is expected to be a complete standard regular expression that is matched agains <expression>. If there is a match (a complete case insensitive match!) then the related <command> is executed. brea is treated just like in the case label. default[:]<command> The default label is executed unconditionally (unless there was a previous label that terminated the execution with break).
Syntax Specification
    switch(<expression>)
    {
        case(<value>)[:]<command>
        [break]
        case(<value>)[:]<command>
        [break]
        ....
        match(<wildcard_expression>)[:]<command>
        [break]
        ....
        regexp(<regular_expression>)[:]<command>
        [break]
        ....
        case(<value>)[:]<command>
        [break]
        ....
        default[:]<command>
        [break]
    }
Examples
# Try to change the 1 below to 2 or 3 to see the results %tmp = 1 switch(%tmp) { case(1): echo \%tmp was 1! break; case(2) echo \%tmp was 2! break; default: echo \%tmp was not 1 nor 2: it was %tmp! break; } # A complexier example: change the 1 in 2 or 3 %tmp = 1 switch(%tmp) { case(1): echo \%tmp was 1! case(2) echo \%tmp was 2! break; default: echo \%tmp was either 1 or something different from 2 (%tmp) break; } # An example with strings %tmp = "This is a test" %tmp2 = "This is not a test" switch(%tmp) { case(%tmp2) echo \%tmp == \%tmp2 break; case(%tmp) { # do not break here echo "Yeah.. it's stupid.. \%tmp == \%tmp :D" } match("*TEST"): echo "Matched *TEST" regexp("[a-zA-Z ]*test"): echo "Matched [a-zA-Z ]*text" regexp("[a-zA-Z ]*not[a-zA-Z ]*"): echo "Matched [a-zA-Z ]*not[a-zA-Z ]*" default: echo This is executed anyway (unless some break was called) break; }

Index, Commands

KVIrc 3.4.0 Documentation
Generated by root at Mon Dec 22 00:58:26 2008