This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

labelled break  RSS feed

 
joshua antony
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
joshua antony
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Wise,
That explanation was just superb.

Regards,
Joshua
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!