0
How do I exit a nested loop?
8 odpowiedzi
+ 3
bool ok = false
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (something){
ok = true;
break;
}
}
if (ok) break;
}
+ 1
a loop nested in what,another loop? function?well I know of the break keyword
+ 1
Can you show us some code ?
I do think breaking out of a nested loop is bad practice.
And you can organise you code different so you do not need the nested loop.
+ 1
A flag. Good. Thanks
0
After a nested loop. One break; exits to external loop. Two break; will not work.
0
Very nice Christian. Perfect. Great!
- 7
U turn off the device