This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

K&B Exam Watch - break & continue

 
Simon Cockayne
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pete Knecht
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joyce,

Thanks for the illumination.

Cheers,

Si.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic