switch语句计算表达式,将表达式的值与case子句匹配,并执行与该case相关的语句。
以下是语法。
switch(variable_expression) {
case constant_expr1: {
// statements;
}
break;
case constant_expr2: {
//statements;
}
break;
default: {
//statements;
}
break;
}
