问题描述
请解释下面的代码:
Please explain below code:
public static void main(String[] args) {
aa:
for(int i=1;i<=3;i++){
bb:
for(int j=1;j<=3;j++){
if(i==2&&j==2){
break aa;
}
System.out.println(i+" "+j);
}
}
}
}
已添加代码块 - OriginalGriff [/ edit]
我的尝试:
我尝试过Java Labeled For Loop程序。
[edit]Code block added - OriginalGriff[/edit]
What I have tried:
I have tried Java Labeled For Loop program.
推荐答案
未标记的break语句终止最内层的switch,for,while或do-while语句,但带标签的break终止外部语句。以下程序BreakWithLabelDemo与前一个程序类似,但使用嵌套for循环来搜索二维数组中的值。当找到该值时,标记的中断终止外部for循环
An unlabeled break statement terminates the innermost switch, for, while, or do-while statement, but a labeled break terminates an outer statement. The following program, BreakWithLabelDemo, is similar to the previous program, but uses nested for loops to search for a value in a two-dimensional array. When the value is found, a labeled break terminates the outer for loop
这就是他在这里发生的事情:当满足条件时,外部循环终止以及内部循环终止。
That's what his happening here: when the condition is met, the outer loop is terminated as well as the inner one.
这篇关于我是新编程的学习者。请任何人解释一下JAVA代码片段。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!