when we use the simple break statement, we can only transfer control from the inner majority of loops to the outer majority (if we have nesting loops). for example
for(int i=0; i < 10; i++){ if(i==5){ break; } } statement x;
just transfers the control to the x operator. But if you use it inside nested loops, then it will work differently.
for(int i=0; i < 10; i++){ for(int j=0; j < 10; j++) if(i==5){ break; } } statement y; } statement x;
in this case, it will send the control to the y operator. If you want to send a control from the innermost loop to any of the outer loops or outside the loop, then you need break statements with labels. Just do it on your own and you will see an interesting result. :)
source share