0
Does writing break; in inner loop only comes out of inner loop or both the loops ??
3 Réponses
+ 6
Aman Jain , I think break applied to the inner loop will stop it , but the outer loop still remains active.
+ 5
Try it for yourself:
#include <stdio.h>
int main() {
int i = 1, j;
while (i <= 5)
{
printf("\ni = %d", i);
j = 1;
while (j <= 5)
{
j++;
printf("\nj = %d", j);
if (j == 2)
{
break;
}
}
i++;
}
return 0;
}
+ 3
Break statement only breaks the innermost loop.