If there are two loops ,one nested in the other, Does the break statement in the inner loop exit the inner loop or the whole two loops? Can anybody clear this? Thanks
yogesh sood
Ranch Hand
Joined: Aug 31, 2000
Posts: 108
posted
0
break statement without label will cause exit from inner most loop or loop in which it is called but labeld break will cause break out oflabeled loop yogi: for (int i=0;i<7;i++) { for( int j=0;j<6;j++) if (j==2) break;//break out of second loop only else if(i==5) break yogi;//break out of first loop } //line7 second break will take control to statement after outer most loop i.e at line 7 Hope this will help :-)
If its green its biology if its stinkks its chemistry if it has numbers it is Maths and if it doesn't work its TECHNOLOGY