Can I use break to exit multiple nested for loops?


Question

Is it possible to use the break function to exit several nested for loops? If so, how would you go about doing this? Can you also control how many loops the break exits?

1
277
9/16/2017 7:29:11 PM

Accepted Answer

AFAIK, C++ doesn't support naming loops, like Java and other languages do. You can use a goto, or create a flag value that you use. At the end of each loop check the flag value. If it is set to true, then you can break out of that iteration.

220
8/10/2009 11:20:14 PM

No, don't spoil it with a break. This is the last remaining stronghold for the use of goto.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon