File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubts about break Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubts about break" Watch "Doubts about break" New topic
Author

Doubts about break

Bin Zhao
Ranch Hand

Joined: Oct 04, 2000
Posts: 73
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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubts about break