0

i m facing a problem for a long time but i could not find any solution

for{ for(){break} } in the inner for loop there will be a condition if it does not satisfy the condition then it will break the inner for loop as well as outer for loop. How can i do that ? Even using break label we can't solve the problem i think..

3rd May 2017, 2:36 PM
Somnath Ghosh
Somnath Ghosh - avatar
4 Antworten
+ 18
int flag=0; for (//stuff) { for (//stuff) { if (!condition) { flag++; break; } } if (flag==1) break; }
3rd May 2017, 2:39 PM
Pixie
Pixie - avatar
+ 10
You don't need a flag. Just use a named label above the outer loop: myLabel: // some example loops for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { // some example condition if (i+j == 5) { break myLabel; } } } Is that what you are looking for?
7th May 2017, 8:17 PM
Tashi N
Tashi N - avatar
+ 4
break in case of a rised flag after every loop. Try to understand Pixie's example and you'll see that you can adapt it to any number of nested loops
7th May 2017, 8:09 PM
seamiki
seamiki - avatar
0
if there are 3-4 for loops
7th May 2017, 6:14 AM
Somnath Ghosh
Somnath Ghosh - avatar