Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how label work ?

 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can someone pls tell how label work and the scope of coverage by label ?



is that means, if mylabel have labeled, the scope for "mylabel" label cover 2 for loop ? thank you very much for explain
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The for statement includes the block it controls.

This is one statement:
for ( i = 1; i <= 10; i++ ) { sum += i; product *= i; }

This is one labeled staement:
myLabel: for ( i = 1; i <= 10; i++ ) { sum += i; product *= i; }

The label only controls the one statement immediately following, so in your example, mylabel controls the first for statement.
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks mike
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic