• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Use of labelled statement in java ?

 
Prince Chauda
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 8
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Pie
    Posts: 64196
    83
    IntelliJ IDE Java jQuery Mac Mac OS X
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    "Prince Chauda", please check your private messages for an important administrative matter.
     
    Rob Spoor
    Sheriff
    Pie
    Posts: 20393
    46
    Chrome Eclipse IDE Java Windows
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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:
     
    Prince Chauda
    Greenhorn
    Posts: 8
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic