• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Use of labelled statement in java ?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Marshal
Posts: 80281
432
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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...
     
    Sheriff
    Posts: 67753
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    "Prince Chauda", please check your private messages for an important administrative matter.
     
    Sheriff
    Posts: 22821
    132
    Eclipse IDE Spring Chrome Java Windows
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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 ?
     
    Legend has it that if you rub the right tiny ad, a genie comes out.
    We need your help - Coderanch server fundraiser
    https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
    reply
      Bookmark Topic Watch Topic
    • New Topic