This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

loops & labels

 
Anupreet Arora
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will be the result of attempting to compile and run the following program?

Am I allowed to use labels anywhere inside code..loop or no loop?
 
Alton Hernandez
Ranch Hand
Posts: 443
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anupreet,
I think your program will fail compilation because the label i2 is proceeded by the variable declaration of j. Labels must immediately follow a block of codes like those enclosed by for-loop, while, or just simply {}.
 
Marlene Miller
Ranch Hand
Posts: 1392
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to JLS 17.7, any statement may have a label prefix.
Identifier : Statement
Now, it is important to know what is Not a Statement.
int i = 1; // Not a Statement
label1 : i = 2;
label2 : i++;
label3 : {}
one: two: three: if (i > 0) break two; else i++;
As far as I can tell, local variable declarations and local class declarations are not Statements.
void m() {
label1 : int i = 1; // No!
label2 : class C {} // No!
}
 
Alton Hernandez
Ranch Hand
Posts: 443
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marlene Miller:
According to JLS 17.7, any statement may have a label prefix.

That's interesting.
In that case, this is also allowed:
label1:;
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic