This question already has answers here:
“loop:” in Java code. What is this, and why does it compile?
(12个答案)
6年前关闭。
我的工作是浏览其他人的代码,当我遇到此for循环时,我试图将其全部弄清楚。
我从未见过这种语法,也无法通过Google搜索在任何地方找到对该语法的引用。谁能告诉我AssetLoop:在做什么?或者只是给我这个概念的名称,这样我就可以做一些毫无头脑的谷歌搜索并阅读一下? :)
(12个答案)
6年前关闭。
我的工作是浏览其他人的代码,当我遇到此for循环时,我试图将其全部弄清楚。
//I don't understand the purpose of assetLoop
assetLoop: for (AssetObject asset : assets) {
//Some code
}
我从未见过这种语法,也无法通过Google搜索在任何地方找到对该语法的引用。谁能告诉我AssetLoop:在做什么?或者只是给我这个概念的名称,这样我就可以做一些毫无头脑的谷歌搜索并阅读一下? :)
最佳答案
这称为标签。
它允许您从嵌套循环中编写break assetLoop
来突破外循环。
它本质上是goto
的有限形式,很少使用。
10-06 01:39