Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between break and continue in a loop

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about the difference between break and continue in the cycle. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

I believe that people who are new to programming are easily confused by the two keywords break,continue, both of which mean to jump out of the loop, but what's the difference between them?

In fact, it is very simple, break is to end the whole cycle, continue is to end the current single cycle, do not understand, look at the following procedures and run the results I think you will understand!

Int x = 0 position while (x = 10)

{

If (x = = 3)

{

Break

}

Printf ("% d\ r\ n", x)

} the running result of the program is: 1 / 2

Analysis: because the program starts to output numbers after entering the while loop, when the if statement is executed and the break statement is run, the break jumps out of the whole loop, so the next step is to execute the code behind the while, and the program ends.

Int x = 0

While (Xerox + < 10)

{

If (x = = 3)

{

Continue

}

Printf ("% d\ r\ n", x)

}

Operation result: 1 2 4 5 6 7 8 9 10

Analysis: this cycle uses continue to jump out of the single loop. When the program runs to XFormul3, execute the continue statement, and the program will skip the subsequent unfinished code in this cycle and directly execute it for 4 times.

The above is the difference between break and continue shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report