• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

K&B Exam Watch - break & continue

 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joyce,

Thanks for the illumination.

Cheers,

Si.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic