If I use a break statement, it will only break inner loop and I need to use some flag to break the outer loop. But if there are many nested loops, the code will
Caution: This answer shows a truly obscure construction.
If you are using GCC, check out this library.
Like in PHP, break can accept the number of nested loops you want to exit.
You can write something like this:
for(int i = 0; i < 1000; i++) {
for(int j = 0; j < 1000; j++) {
if(condition) {
// break two nested enclosing loops
break(2);
}
}
}