当前位置:网站首页>为什么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就不会进行++了,如下图所示。

基础不牢地动山摇啊 !
边栏推荐
- [OpenGL] notes 29. Advanced lighting (specular highlights)
- (7) Web security | penetration testing | how does network security determine whether CND exists, and how to bypass CND to find the real IP
- [opencv learning] [Canny edge detection]
- Jerry's watch stops ringing [article]
- C operator
- Sensor adxl335bcpz-rl7 3-axis accelerometer complies with rohs/weee
- Unity SKFramework框架(十二)、Score 计分模块
- Principle analysis of security rememberme
- To bypass obregistercallbacks, you need to drive the signature method
- Oracle from entry to mastery (4th Edition)
猜你喜欢

PR usage skills, how to use PR to watermark?

Unity SKFramework框架(十四)、Extension 扩展函数
![[200 opencv routines] 100 Adaptive local noise reduction filter](/img/89/9e9b667dd28cb25af005b6028ef26c.jpg)
[200 opencv routines] 100 Adaptive local noise reduction filter

【蓝桥杯选拔赛真题43】Scratch航天飞行 少儿编程scratch蓝桥杯选拔赛真题讲解
![Jerry's watch ringtone audition [article]](/img/18/905c4b64443f4efca55188e36f4b28.jpg)
Jerry's watch ringtone audition [article]

Ltc3307ahv meets EMI standard, step-down converter qca7005-al33 phy

Js4day (DOM start: get DOM element content, modify element style, modify form element attributes, setinterval timer, carousel Map Case)

Word efficiency guide - word's own template

Unity skframework framework (XXI), texture filter map resource filtering tool

Unity skframework framework (XIV), extension extension function
随机推荐
How can attribute mapping of entity classes be without it?
Security RememberMe原理分析
JS逆向之巨量创意signature签名
Post order traversal sequence of 24 binary search tree of sword finger offer
mac(macos Monterey12.2 m1) 个人使用php开发
Jerry's watch ringtone audition [article]
The second anniversary of the three winged bird: the wings are getting richer and the take-off is just around the corner
ADB basic commands
C operator
Variable, "+" sign, data type
How to modify the error of easydss on demand service sharing time?
Five best software architecture patterns that architects must understand
Operation tutorial: how does easydss convert MP4 on demand files into RTSP video streams?
【OpenGL】笔记二十九、高级光照(镜面高光)
Js2day (also i++ and ++i, if statements, ternary operators, switch, while statements, for loop statements)
Unity skframework framework (XIII), question module
Clean up system cache and free memory under Linux
net share
Get started REPORT | today, talk about the microservice architecture currently used by Tencent
Independent and controllable 3D cloud CAD: crowncad enables innovative design of enterprises