当前位置:网站首页>为什么switch 的default后面要跟break?
为什么switch 的default后面要跟break?
2022-07-02 10:08:00 【基础不牢 地动山摇】
这个很多人一开始会以为是5其实结果是7。
原因:因为switch再遇见 匹配的条件是会一直默认向下执行,所以在匹配到default中的条件后会向下执行case 1 和case 2中的条件。
如下图所示在default匹配到之后会执行下面两个条件导致b=4。
而在case 1: 处增加break之后如下图所示,只会执行一次b++,如下图所示。
而在defaul后面加上break之后b就不会进行++了,如下图所示。
基础不牢地动山摇啊 !
边栏推荐
- 【云原生数据库】遇到慢SQL该怎么办(上)?
- [error record] cannot open "XXX" because Apple cannot check whether it contains malware
- 研究表明“气味相投”更易成为朋友
- Js1day (input / output syntax, data type, data type conversion, VaR and let differences)
- Jerry's watch delete alarm clock [chapter]
- Independent and controllable 3D cloud CAD: crowncad enables innovative design of enterprises
- Should I have a separate interface assembly- Should I have a separate assembly for interfaces?
- Std:: vector batch import fast de duplication method
- Crowncad (crown CAD), the first fully independent 3D CAD platform based on Cloud Architecture in China
- Jerry's watch stops ringing [article]
猜你喜欢
Unity SKFramework框架(十四)、Extension 扩展函数
Unity skframework framework (XX), VFX lab special effects library
MAC (MacOS Monterey 12.2 M1) personal use PHP development
Unity SKFramework框架(二十)、VFX Lab 特效库
Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
[200 opencv routines] 100 Adaptive local noise reduction filter
Mobile layout (flow layout)
3 a VTT terminal regulator ncp51200mntxg data
Word efficiency guide - word's own template
研究表明“气味相投”更易成为朋友
随机推荐
Js2day (also i++ and ++i, if statements, ternary operators, switch, while statements, for loop statements)
Nohup command
难忘阿里,4面技术5面HR附加笔试面,走的真艰难真心酸
Everyone wants to eat a broken buffet. It's almost cold
Word efficiency guide - word's own template
[true topic of the Blue Bridge Cup trials 43] scratch space flight children's programming explanation of the true topic of the Blue Bridge Cup trials
完全自主可控三维云CAD:CrownCAD便捷的命令搜索,快速定位所需命令具体位置。
Unity SKFramework框架(十五)、Singleton 单例
Jerry's watch reads the alarm clock [chapter]
linux下清理系统缓存并释放内存
Unity skframework framework (XVIII), roamcameracontroller roaming perspective camera control script
What are eNB, EPC and PGW?
Redis database persistence
leetcode621. 任务调度器
[opencv learning] [image filtering]
2022零代码/低代码开发白皮书【伙伴云出品】附下载
(7) Web security | penetration testing | how does network security determine whether CND exists, and how to bypass CND to find the real IP
文件的下载与图片的预览
Uniapp develops wechat applet Tencent map function and generates sig signature of location cloud
伙伴云表格强势升级!Pro版,更非凡!