[NAME] ALL.dao.control.switch-case [TITLE] Switch-Case Control [DESCRIPTION] Switch-case control provides a convenient way to branch the code and choose a block of c ode to execute based on the value of a object. 0.1 Definition 1 SwitchCaseStmt ::= 'switch' '(' Expression ')' '{' 2 { 'case' Expression [ ( ',' | '...' ) Expression ] ':' ControlBlock } 3 [ 'default' ':' ControlBlock ] 4 '}' A switch-case statement generally looks like the following: 1 switch( expresssion ){ 2 case C_1 : block_1 3 case C_2 : block_2 4 case C_3 : block_3 5 ... 6 default: block0 7 } If the expresssion equals to C_i, block_i will be executed. Here C_i must be a constant, but they can be of different types, that means, you can mix numbers and strings as case v alues. Unlike in C/C++, no break statement is required to get out of the switch. If you want to execute the same block of codes for different case values, you just need t o put them together in the same case: 1 switch( expresssion ){ 2 case C1, C2, C3 : 3 block3 4 ... 5 default: block0 6 } As a simple example, 1 var a = "a"; 2 switch( a ){ 3 case 1, "a" : io.write("case 1 or a"); 4 default : io.write("case default"); 5 }