patterncppCritical
Can I use break to exit multiple nested 'for' loops?
Viewed 0 times
loopsuseforexitmultiplebreakcannested
Problem
Is it possible to use the
If so, how would you go about doing this? Can you also control how many loops 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?Solution
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.
Context
Stack Overflow Q#1257744, score: 301
Revisions (0)
No revisions yet.