这个错误意味着break语句中缺少标签z? [英] What is this error mean label z is missing in break statement?
本文介绍了这个错误意味着break语句中缺少标签z?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,在下面的代码我试图使用break和标签出来for循环,但我收到以下错误。 标签Z缺失。
请帮我解释下面的代码。请注意为什么会出现此错误。
Hi in the below code i am trying to come out of for loop using break and label but i am getting the following error. Label Z is missing.
Please help me the code is given below. And please mention why this error occurs.
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);
}
}
推荐答案
你正在收到错误,因为在你的代码标签中z:没有包含任何循环:
You are getting the error because in your code label z: is not enclosing any loop:
尝试以下代码:我刚刚在标签z之后添加了一对括号:你将不会出现任何编译错误,您的代码将运行。
Try the below code: I have just added a pair of braces after label z: you will not get any compilation error and your code will run.
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);
}
}
}
这篇关于这个错误意味着break语句中缺少标签z?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文