Branches and Loops (16/42 Branch:switch switch (expression )expression is a scalar or string of constants case value 1, statement 1 If the value of expression is equal to statement valuel,then the first code block will be statement 2 group 1 executed,and the program will jump to the first statement following the end of the case value 2, switch construct. statement 1 statement 2 statement group 2 end @月济大学 TONGJI UNIVERSITY
Branches and Loops (16/42) Branch: switch switch ( expression ), case value 1, statement 1 statement 2 ... case value 2, statement 1 statement 2 ... ... end expression is a scalar or string of constants If the value of expression is equal to value1 ,then the first code block will be executed ,and the program will jump to the first statement following the end of the switch construct. statement group 1 statement group 2
Branches and Loops (17/42 Branch:switch switch expression ) case {value set 1), statement 1 statement statement 2 group 1 4 case {value set 2,value set 3,value set 4), statement 1 statement statement 2 If some values are supposed to execute the group 2 same statement,they have to be included in the same single block by enclosing them into brackets. otherwise, statement 1 statement2 Optional statement group that is executed if none of the cases is satisfied 2 end 同碎大学 TONGJI UNIVERSITY
Branches and Loops (17/42) Branch: switch switch ( expression ), case {value set 1}, statement 1 statement 2 ... case {value set 2,value set 3,value set 4}, statement 1 statement 2 ... ... otherwise, statement 1 statement 2 ... end statement group 1 statement group 2 If some values are supposed to execute the same statement, they have to be included in the same single block by enclosing them into brackets. Optional statement group that is executed if none of the cases is satisfied