• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 79475
379
  • 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: 67749
    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: 22788
    131
    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 ?
    reply
      Bookmark Topic Watch Topic
    • New Topic