用Java标记语句块? [英] Labeled Statement block in Java?
问题描述
当我发现一段代码被 scan:{}
块包围时,我浏览了一些基础Java对象。以下代码来自String类中的toLowerCase()方法。
I was browsing through some of the base Java objects when I found a section of code surrounded by a scan: {}
block. The following code is from the toLowerCase() method inside the String class.
scan: {
for (firstUpper = 0 ; firstUpper < len; ) {
char c = value[firstUpper];
if ((c >= Character.MIN_HIGH_SURROGATE)
&& (c <= Character.MAX_HIGH_SURROGATE)) {
int supplChar = codePointAt(firstUpper);
if (supplChar != Character.toLowerCase(supplChar)) {
break scan;
}
firstUpper += Character.charCount(supplChar);
} else {
if (c != Character.toLowerCase(c)) {
break scan;
}
firstUpper++;
}
}
return this;
}
有人可以解释一下扫描:{}
块用于此语法的来源和位置?除非在三元运算符中使用,否则我还没有在Java中看到像这样的字后出现冒号。
Could someone please explain what the scan:{}
block is used for and where this syntax comes from? I've yet to see a colon after a word like this in Java unless used in a ternary operator.
谢谢!
编辑:更新标题以正确匹配已回答的问题。
Updated title to correctly match answered question.
推荐答案
此处,扫描:
只是一个标签。 break< label>
语法允许人们突破外部循环,并模拟某些形式的 goto
声明。语法记录在 JLS :
Here, scan:
is simply a label. The break <label>
syntax allows one to break out of outer loops, and to simulate some forms of the goto
statement. The syntax is documented in the JLS:
带有标签
标识符的
尝试将控制转移到封闭的带标签的声明(第14.7节),该声明具有相同的break
语句标识符
作为其标签;此语句称为中断目标,然后立即正常完成。在这种情况下,中断目标不必是开关
,而
,执行
或for
声明。
A
break
statement with labelIdentifier
attempts to transfer control to the enclosing labeled statement (§14.7) that has the sameIdentifier
as its label; this statement, which is called the break target, then immediately completes normally. In this case, the break target need not be aswitch
,while
,do
, orfor
statement.
这篇关于用Java标记语句块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!