简体   繁体   English

SCJP带标签

[英]SCJP with label

Below will be compilation fail due to "label z is missing" but if I just move z: to one step below after o = o + 2 then that will work? 由于“缺少标签z”,下面的编译会失败,但如果我只是在o = o + 2之后将z:移动到下面的一步,那么这将有效吗? What is the logic behind this? 这背后的逻辑是什么?

public class Breaker {
static String o = "";

public static void main(String[] args) {
z: 
o = o + 2;
for (int x = 3; x < 8; x++) {
    if (x == 4)
    break;
    if (x == 6)
    break z;
    o = o + x;
}
System.out.println(o);
}
}

You cannot put the labels everywhere in the code. 您无法在代码中随处放置标签。 it should be only before statements. 它应该只在陈述之前。 in this case labelname: for(;;){} Here's the documentation 在这种情况下labelname: for(;;){}这是文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM