It's not a secret anymore!
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

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?
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
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:
subject: Doubts about break
It's not a secret anymore!