2

I have the job of going through another's code and I'm trying to figure it all out when I came across this for loop.

//I don't understand the purpose of assetLoop
assetLoop: for (AssetObject asset : assets) {

     //Some code
}

I've never seen this syntax and I can't find any reference to it anywhere through my google searches. Can anyone tell me what assetLoop: is doing? Or simply give me the name of this concept so I can do some non-mindless googling and read about it? :)

Julian
  • 1,665
  • 2
  • 15
  • 33

2 Answers2

4

This is called a label.

It allows you to write break assetLoop from a nested loop to break out of the outer loop.

It's essentially a limited form of goto, and is rarely used.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

It's a label. You can put them on any statement. break assetLoop; will break out of that loop, even if the break statement is within another for, while, do-while or switch statement. Similarly continure assetLoop; will jump to the next iteration of the loop.

Tom Hawtin - tackline
  • 145,806
  • 30
  • 211
  • 305