switch ,开关语句(多重分支语句)
case ,开关语句中的分支标记
default ,开关语句中的“其他”分支,可选。
The C switch Statement
C语言中switch分支表达形式
The switch and case statements help control complex conditional and branching operations. The switch statement transfers control to a statement within its body.
switch和case声明帮助控制复杂情况和分支操作,switch表达式控制转移至其内部的分支表达式。
switch (expression )
{
case constant-expression : expression;
case constant-expression : expression;
…
case constant-expression : expression;
default : statement;
}
switch(表达式)
{
case 常量表达式1: 语句1;
case 常量表达式2: 语句2;
…
case 常量表达式n: 语句n;
default: 语句n+1;
}
Control passes to the statement whose case constant-expression matches the value of switch ( expression ). The switchstatement can include any number of case instances, but no two case constants within the same switch statement can have the same value. Execution of the statement body begins at the selected statement and proceeds until the end of the body or until a break statement transfers control out of the body.
switch语句的表达式控制case的程序执行入口,switch的表达式中可以是其内部case的常量,也可以是其他常量。case中的常量表达式不能相同,执行时只要switch中的值和case值相同则从此case执行语句开始执行,知道遇到第一个break或者执行完所有的执行语句结束。
Use of the switch statement usually looks something like this:
switch ( expression