• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What does this line do?

 
Mat Cauthon
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Keith Lynn
Ranch Hand
Posts: 2399
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Pratibha Malhotra
Ranch Hand
Posts: 199
  • 0
  • Mark post as helpful
  • send pies
  • 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,
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic