#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, k, l;
i = j = 0;
clrscr();
for(k = 0; k < 3; k++)
{
printf("Flag A\t");
for(l = 0; l < 2; l++)
{
printf("Flag B\t");
if(i == 5)
{
printf("Flag C\t");
if(j == 5)
{
printf("Flag D\n");
break;
}
}
i++;
j++;
}
}
printf("Value of i=%d,j=%d,k=%d,l=%d", i, j, k, l);
getch();
}
When I trace the output of above code, it is:
Flag A Flag B Flag B Flag A Flag B Flag B Flag A Flag B Flag B Flag C Flag D
values of i=5 j=5 k=3 l=1
I get the same answer manually. Also, my question is: when I trace the output, the break condition occurs when i=5 and j=5. At that time, control breaks two if
loops and the l
for
loop, and gets started from the next iteration of the k
for
loop. Is that the regular behavior of the break
(cracks 3 nested loops when it is nested inside 3 loops), or does it happen due to the combination of the loops? What happens if I use other possible combinations of the loops? Please explain behavior of the break
statement when it's used with multiple combinations of other loops. Please explain behavior with switch
also.