aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes labelled break Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "labelled break" Watch "labelled break" New topic
Author

labelled break

joshua antony
Ranch Hand

Joined: Jun 05, 2006
Posts: 117
The labeled varieties are needed only in situations where you have a
nested loop, and need to indicate which of the nested loops you want to break from,or from which of the nested loops you want to continue with the next iteration.


So based on above, in the below code HELO and JILL can be used to break out of which loop?

Matt Russell
Ranch Hand

Joined: Aug 15, 2006
Posts: 165
There are no loops that you can use HELO and JILL to break out of. The "while (c < 8)" loop is labeled by JACK. The other labels do not refer to a loop.

Quite why Java lets you label statements other than loops, I don't know.


Matt
Inquisition: open-source mock exam simulator for SCJP and SCWCD
joshua antony
Ranch Hand

Joined: Jun 05, 2006
Posts: 117
Quite why Java lets you label statements other than loops, I don't know.


Exactly, thats the thing I wanted to know.
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
Why label statement causes compile time error?:

The use of labels in loops and breaks has the following rules:
1. Any statement can have a label.
2. If a break statement has a label it must be the label of an enclosing statement.
3. If a continue statement has a label it must be the label of an enclosing loop.

For example

[ October 23, 2006: Message edited by: wise owen ]
joshua antony
Ranch Hand

Joined: Jun 05, 2006
Posts: 117
Thanks Wise,
That explanation was just superb.

Regards,
Joshua
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: labelled break