• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

K&B Exam Watch - break & continue  RSS feed

 
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.
 
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.
 
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!