Section A.7. Execution Flow


A.7. Execution Flow

MSH offers two mechanisms for controlling the flow of script execution: the if statement and the switch statement.

A.7.1. if Statement

 if (<test 1>) { <block 1> } elseif (<test2>) { <block 2> } ... else { <block 3> }

As soon as one of the tests evaluates to true, the corresponding block is executed and no other tests are performed. The elseif and else parts of the statement are optional.

A.7.2. switch Statement

 switch (<expression>) {     <value> { <block 1> }             # case 1     {<test>} { <block 2> }            # case 2     default { <block 3> }             # case 3 }

In case 1, MSH performs a test on the expression and value and, if they are equal, executes the first block. In case 2, MSH evaluates the test (in which $_ is used for the value of <expression>), and if the test evaluates to true, the second block is run. There may be many instances of these two cases, each using a different value or test. The default case (case 3) may only occur once and its associated block is run only if none of the other cases results in a match. Switch statements do not terminate after a match is made; instead, the blocks associated with all matching tests are run.




Monad Jumpstart
Monad Jumpstart
ISBN: N/A
EAN: N/A
Year: 2005
Pages: 117

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net