aspose file tools*
The moose likes Beginning Java and the fly likes Use of labelled statement in java ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Use of labelled statement in java ?" Watch "Use of labelled statement in java ?" New topic
Author

Use of labelled statement in java ?

Prince Chauda
Greenhorn

Joined: Feb 13, 2008
Posts: 8
We can use labels at anywhere except before the declaration , but without a "goto" statements we can never call those labels.
Then what is the use for such labels ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
Two possible answers:
  • No use at all. They were leftovers from C/C++ which ought to have been deleted from the language in its infancy.
  • You can precede the name of a label by the keywords break and continue
  • Somebody else may provide different opinions.

    You can also precede a label with the keyword case, but that is something different.
    Prince Chauda
    Greenhorn

    Joined: Feb 13, 2008
    Posts: 8
    Campbell Ritchie wrote:Two possible answers:
  • No use at all. They were leftovers from C/C++ which ought to have been deleted from the language in its infancy.
  • You can precede the name of a label by the keywords break and continue
  • Somebody else may provide different opinions.

    You can also precede a label with the keyword case, but that is something different.

    Thanks for your opinions ... still waiting for more...
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61218
        
      66

    "Prince Chauda", please check your private messages for an important administrative matter.


    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    Rob Spoor
    Sheriff

    Joined: Oct 27, 2005
    Posts: 19695
        
      20

    Labelled statements should only be used with nested loops, where an inner loop needs to break or continue one of the outer loops. For instance:


    SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
    How To Ask Questions How To Answer Questions
    Prince Chauda
    Greenhorn

    Joined: Feb 13, 2008
    Posts: 8
    Rob Prime wrote:Labelled statements should only be used with nested loops, where an inner loop needs to break or continue one of the outer loops. For instance:


    Since labels can be applied to any statements except before declaration , but break and continue should be within a loop. So my question was that what is the benefit of of such labels which are outside the loop or before any other statements ?
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Use of labelled statement in java ?