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..
4 Réponses
+ 18
int flag=0;
for (//stuff)
{
for (//stuff)
{
if (!condition)
{
flag++;
break;
}
}
if (flag==1)
break;
}
+ 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?
+ 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
0
if there are 3-4 for loops