This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B Exam Watch - break & continue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K&B Exam Watch - break & continue" Watch "K&B Exam Watch - break & continue" New topic
Author

K&B Exam Watch - break & continue

Simon Cockayne
Ranch Hand

Joined: Dec 09, 2000
Posts: 214
Hi,

K&B page 231 says:

"continue statements must be inside a loop; oitherwise, you'll get a compiler error. break statements must be used inside either a loop or switch statemnts. (Note: This does not apply to labeled break statements".

What is the note driving at?

Where can one use a "labeled break" that is not inside a loop or switch?


Cheers,

Si.


SCJP 1.4 (93%)<br />SCJD (In progress. It can run, but it can't hide...)
Pete Knecht
Ranch Hand

Joined: Mar 30, 2005
Posts: 33
I interpret this to sort of refer to the labeled-break syntax as a whole, where the actual *label* can be outside the loop, but the 'break:label;' part will still be inside some loop or other. I don't think 'break' can appear outside any loop (or switch).
Simon Cockayne
Ranch Hand

Joined: Dec 09, 2000
Posts: 214
Hey Pete,

Thanks for the feedback.

I do get what you are saying...but I reckon the text in the book is misleading.

Even a labelled break has to appear in the loop/switch and it is only, as you say, the label that appears outside.

So...in either case, the break statement itself is inisde.

Cheers,

Si.
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Hi Si,

break statements must be used inside either a loop or switch statemnts. (Note: This does not apply to labeled break statements".

What is the note driving at?


For break statement with label, it does not have to be inside a loop or switch statement. Here is an example:



Have a look at JLS 14.14 for details and example.

Joyce
[ April 10, 2005: Message edited by: Joyce Lee ]
Simon Cockayne
Ranch Hand

Joined: Dec 09, 2000
Posts: 214
Joyce,

Thanks for the illumination.

Cheers,

Si.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: K&B Exam Watch - break & continue
 
Similar Threads
K&B on labeled break
confused about labled break
Label association doubt
K&B SCJP5 Reconcile of ExamWatches
Can label be placed before switch?