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

What does this line do?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got this out of my text book for my programming principles class. This code shows name overloading in Java. The line in question is in bold.


[ October 01, 2006: Message edited by: Marilyn de Queiroz ]
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is a label. You can find the specification for it in Section 14.7 of the Java Language Specification, Third Edition.
[ October 01, 2006: Message edited by: Keith Lynn ]
 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it is a way to label a statement. Main purpose behind same is to to provide a mark to a particular line of code.

It is primarily used in Loops for decision making for flow of control and is useful with break and continue operations


outer:
for( i=0; i<10; i++ ){
for( j=10; j>0; j--){
if( j == 5 ) {
break outer; // exit entire loop-labeled as outer
}
}
}



HTH,
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, so now that you've learned what a label is, please forget about it and don't use it in your own code ever again...

You don't need this construction, it makes code hard to read and follow. A label and a break statement to jump to the label are more or less like a "goto" statement, the statement that quickly makes programs a messy jumble (spaghetti code).
 
There is no greater crime than stealing somebody's best friend. I miss you tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic