break Exit the nearest loop or switch

break Exit the nearest loop or switch

break exits the nearest loop or switch. It leaves one level and cannot exit ordinary if; in switch, it prevents fall-through but is optional.

CategoryControl flow
KindKeyword / Statement
C standardC89 / C90

📝 Syntax

while (1) { if (cond) break; }

▶ Example

Edit the C code below and click Run; the server compiles and executes it:

Output:

stopped at 3

📚 Related Tutorials

❓ FAQ

QCan one break exit two levels of nested loops?
ANo. It terminates only the nearest enclosing loop or switch. To exit multiple levels, refactor into a function and return, use a clear state flag, or, where appropriate, use goto for centralized cleanup.
QCan break appear inside an ordinary if statement?
AOnly when that if is inside a loop or switch; break then terminates that enclosing statement. An if by itself does not make break valid without an enclosing loop or switch.
QIs forgetting break in a switch branch always a compilation error?
AUsually not; the syntax itself is valid, and execution continues into subsequent labels. This is called fall-through. If code sharing was not intentional, the result may be unexpected, so enable relevant compiler warnings.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏