带标签的SCJP [英] SCJP with label

查看:72
本文介绍了带标签的SCJP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下将由于缺少标签z"而导致编译失败,但是如果我只是在o = o + 2之后将 z:移至下一个步骤,那行得通吗?这背后的逻辑是什么?

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? 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);
}
}

推荐答案

您不能在代码中到处放置标签.它只能在声明之前.在这种情况下labelname: for(;;){}这是文档

You cannot put the labels everywhere in the code. it should be only before statements. in this case labelname: for(;;){} Here's the documentation

这篇关于带标签的SCJP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆