当前位置:网站首页>判断语句_switch与case
判断语句_switch与case
2022-08-05 04:52:00 【乖女子@@@】
[1]语法
switch后面跟随的值可以是值也可为表达式,但是case后面仅能为 值!
switch (值/表达式){
case value1:
statements1 // 当表达式/值的结果等于 value1 时,则执行该代码
break;
case value2:
statements2 // 当表达式/值的结果等于 value2 时,则执行该代码
break;
......
case valueN:
statementsN // 当表达式/值的结果等于 valueN 时,则执行该代码
break;
default :
statements // 如果没有与表达式/值相同的值,则执行该代码
}
[2]比较过程
switch 语句根据表达式的值,依次与 case 子句中的值进行比较:
- 如果两者相等,则执行其后的语句段,当遇到 break 关键字时则跳出整个 switch 语句。
- 如果不相等,则继续匹配下一个 case。
- switch 语句包含一个可选的 default 关键字,如果在前面的 case 中没有找到相等的条件,则执行 default 后面的语句段
- 比较过程为
全等!
边栏推荐
猜你喜欢
![[BJDCTF2020]EasySearch](/img/60/464de3bcdda876171b9f61ad31bff1.png)
[BJDCTF2020]EasySearch

App快速开发建设心得:小程序+自定义插件的重要性

Excel画图

【学生毕业设计】基于web学生信息管理系统网站的设计与实现(13个页面)

Day019 方法重写与相关类的介绍
![[BJDCTF2020] EasySearch](/img/60/464de3bcdda876171b9f61ad31bff1.png)
[BJDCTF2020] EasySearch

Error creating bean with name ‘configDataContextRefresher‘ defined in class path resource
![[MRCTF2020] PYWebsite](/img/d4/57e8e5ee45b742894679f3f5671516.png)
[MRCTF2020] PYWebsite

C+ +核心编程

Learning and finishing of probability theory 8: Geometric and hypergeometric distributions
随机推荐
社区分享|腾讯海外游戏基于JumpServer构建游戏安全运营能力
[BSidesCF 2019]Kookie
开发属于自己的node包
dedecms dream weaving tag tag does not support capital letters fix
Day14 jenkins deployment
服务器磁盘阵列
【8.3】代码源 - 【喵 ~ 喵 ~ 喵~】【树】【与】
概率论的学习和整理8: 几何分布和超几何分布
Please write the SparkSQL statement
大学物理---质点运动学
Is the NPDP certificate high in gold content?Compared to PMP?
How to identify false evidence and evidence?
The log causes these pits in the thread block, you have to guard against
Cron(Crontab)--use/tutorial/example
[BJDCTF2020] EasySearch
The solution to the failure to read channel information when dedecms generates a message in the background
uboot开启调试打印信息
Analyses the mainstream across technology solutions
No regrets, the appium automation environment is perfectly built
【学生毕业设计】基于web学生信息管理系统网站的设计与实现(13个页面)