wood burning stoves
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes break , continue with label 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 "break , continue with label" Watch "break , continue with label" New topic

break , continue with label

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
I understand use of break & continue keywords :
break : it stops the control & moves it to out of loop .
continue : it stops the control & moves the control to the next iteration .

But I am confuse when we used this two with label . Can any body explain with short example .

I hope the question is clear .

Thanks a lot .
Jay Ashar
Ranch Hand

Joined: Oct 13, 2002
Posts: 208
Break statement when used with label terminates the labelled statement and flow of control is transferred to statement following labelled statement.
continue-label statement is used to skip over the current iteration, usually used with nested loops. Continue statement will skip the current iteration but if you have nested loop and you want to skip the iteration for outer loop you can use continue with label.

SCJP 1.4<br />SCWCD 1.3
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Both will do their work same as they do in case of label also , just one difference is that , they use loop ( for moving control ) which we mentioned by label .

Like in this case break is moving control out of inner loop .

And in this case , we specified which for loop it should use for moving control by label .

Is everything is right ?

Thanks .
Jay Pawar
Ranch Hand

Joined: Aug 27, 2004
Posts: 411
Yes... break with label a will terminate the loop with index i.

Cheers,<br />Jay<br /> <br />(SCJP 1.4)<br />Heights of great men were not achieved in one day, they were toiling day and night while their companions slept.
I agree. Here's the link: http://aspose.com/file-tools
subject: break , continue with label
It's not a secret anymore!