"环:"在Java代码中。这是什么,为什么编译? [英] "loop:" in Java code. What is this, why does it compile?
本文介绍了"环:"在Java代码中。这是什么,为什么编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这段代码让我盯着我的屏幕看几分钟:
This code just made me stare at my screen for a few minutes:
loop:
for (;;) {
// ...
}
(第137行)
我以前从未见过这个,我不知道Java有一个循环关键字(Netbeans甚至没有像关键字那样着色它) ,它可以用JDK 6编译好。
I have never seen this before, and I had no idea Java has a "loop" keyword (Netbeans doesn't even color it like a keyword), and it does compile fine with JDK 6.
有人能解释一下这个吗?
Can someone explain this to me?
推荐答案
它不是关键字
它是标签
。
用法:
label1:
for (; ; ) {
label2:
for (; ; ) {
if (condition1) {
// break outer loop
break label1;
}
if (condition2) {
// break inner loop
break label2;
}
if (condition3) {
// break inner loop
break;
}
}
}
文档。
这篇关于"环:"在Java代码中。这是什么,为什么编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文