5

I have never come across such expression in Java. It is not even a switch case

 //no code above to make it look like a switch case or loop

 abc: {
    // do some stuff
      break abc;
 }

Do you have any idea what this does?

user2864740
  • 60,010
  • 15
  • 145
  • 220
David Prun
  • 8,203
  • 16
  • 60
  • 86
  • 5
    It's a [label](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html) followed by a block. – rgettman Mar 11 '14 at 21:28
  • Looks like named block to be used with goto – Martin Perry Mar 11 '14 at 21:28
  • 1
    @MartinPerry - Except that there is no `goto` in Java. – Hot Licks Mar 11 '14 at 21:31
  • http://stackoverflow.com/questions/14147821/labeled-statement-block-in-java – user2864740 Mar 11 '14 at 21:31
  • 1
    In the above code segment, `break abc;` will cause control to flow to the first statement following the `}` closing the block labeled "abc". `continue abc;` would cause control to flow to the first statement in the so-labeled block. (This is really only useful when you want to break/continue from several levels deep in a nested block structure.) – Hot Licks Mar 11 '14 at 21:34

3 Answers3

1
abc:

is a label and {} introduces a new scope for that block.

P.P
  • 117,907
  • 20
  • 175
  • 238
1

This is likely a label referring to the code enclosed by the block. This allows you to transfer the flow of the program with more control as opposed to something like breaking out of a while loop.

Brian
  • 7,098
  • 15
  • 56
  • 73
1

They are labels, see http://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html for a complete explanation.

Mike B
  • 5,390
  • 2
  • 23
  • 45