16. What if I Want to Stop in the Middle of a Loop?
Use break and continue
This chapter doesn’t teach you how to use another kind of loop. Instead, this chapter extends the information you learned in the last two chapters. There are ways to control the while
loop in addition to a relational test, and you can change the way a for
loop operates via means other than the counter variable.
The break
and continue
statements let you control loops for those special occasions when you want to quit a loop early or repeat a loop sooner than it would normally repeat.
Take a break
The break
Get Absolute Beginner’s Guide to C, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.