switch statement

来自cppreference.com

 
 
C语言编写
大会的主题
Original:
General topics
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
预处理器
评论
关键字
ASCII表
转义序列
C
流量控制
Original:
Flow control
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
条件执行语句
Original:
Conditional execution statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
switch statement
迭代语句
Original:
Iteration statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
跳转语句
Original:
Jump statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
功能
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
函数声明
的历史。内嵌说明
类型
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
规范
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
CV符
存储类说明
alignas说明 (C99)
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
表达式
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
为了评价
其他运营商
运营商
运算符的优先级
实用工具
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
属性 (C99)
转换
杂项
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
内联汇编
 
执行代码的整体参数值
Original:
Executes code according to value of an integral argument
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
使用一个或几个,满分许多分支的代码根据积分值需要被执行.
Original:
Used where one or several out of many branches of code need to be executed according to an integral value.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目录

[编辑] 语法

switch ( expression ) {
case constant_expression1 :
statement1 (可选的)
case constant_expression2 :
statement2 (可选的)
... ... ...
case constant_expressionn :
statementn (可选的)
default: default_statement (可选的)

}

[编辑] 解释

expression应是一个表达式,转换为一个整数值.
Original:
expression shall be an expression, convertible to an integer value.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
所有constant_expressions必须是常量表达式,转换为一个整数值,这是唯一在此switch声明
Original:
All constant_expressions shall be constant expressions, convertible to an integer value, which is unique within this switch statement
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
如果expression评估值,等于值的定义constant_expressionistatementi(如果有的话)和所有后续语句(除了default_statement,如果存在的话)被执行。如果该值的expression不匹配任何的constant_expressions,在default_statement执行如果存在的话.
Original:
If the expression evaluates to a value, equal to the value of one of the defined constant_expressioni, the statementi (if present) and all subsequent statements (except default_statement, if present) are executed. If the value of the expression does not match any of the constant_expressions, the default_statement is executed if present.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
可以使用。在这种情况下,执行的switch声明终止.
Original:
It is useful to note, that if the execution of subsequent statements is undesirable, the
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 关键字

switch, case, default

[编辑] 为例