当前位置:网站首页>判断语句_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 后面的语句段
- 比较过程为
全等!
边栏推荐
- App rapid development and construction experience: the importance of small programs + custom plug-ins
- Cron(Crontab)--使用/教程/实例
- Four-digit display header design
- ansible各个模块详解
- LAB 信号量实现细节
- How to solve complex distribution and ledger problems?
- 请写出SparkSQL语句
- Error creating bean with name ‘configDataContextRefresher‘ defined in class path resource
- 仪表板展示 | DataEase看中国:数据呈现中国资本市场
- AUTOCAD - dimension association
猜你喜欢
随机推荐
数字孪生技术在电力系统中的应用现状
[8.3] Code Source - [meow ~ meow ~ meow~] [tree] [and]
Redis - 13. Development Specifications
Cron(Crontab)--使用/教程/实例
【学生毕业设计】基于web学生信息管理系统网站的设计与实现(13个页面)
Analyses the mainstream across technology solutions
1007 Climb Stairs (贪心 | C思维)
【8.1】代码源 - 【第二大数字和】【石子游戏 III】【平衡二叉树】
【cesium】加载并定位 3D Tileset
Why did you start preparing for the soft exam just after the PMP exam?
机器学习概述
【转】什么是etcd
1007 Climb Stairs (greedy | C thinking)
Develop your own node package
Error creating bean with name ‘configDataContextRefresher‘ defined in class path resource
The first performance test practice, there are "100 million" a little nervous
狗仔队:表面编辑多视点图像处理
Mini Program_Dynamic setting of tabBar theme skin
【cesium】3D Tileset 模型加载并与模型树关联
Is the NPDP certificate high in gold content?Compared to PMP?




![[MRCTF2020] Ezpop (detailed)](/img/19/920877ca36d1eda8d118637388ab05.png)




