我是新编程的学习者。请任何人解释一下JAVA代码片段。 [英] I am new programming learner. Please any one explain following JAVA code snippet.

查看:108
本文介绍了我是新编程的学习者。请任何人解释一下JAVA代码片段。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请解释下面的代码:





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.

推荐答案

见这里:

分支语句(The Java™Tutorials) [ ^ ]

它说:

See here:
Branching Statements (The Java™ Tutorials)[^]
It says:
引用:

未标记的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.


有一个工具可以让你看到你的代码在做什么,它的名字是调试器。

这也是一个很好的学习工具,因为它向你展示了现实,你可以看到哪个期望与现实相符。



使用调试器查看你的代码在做什么。只需设置断点并查看代码执行情况,调试器允许您逐行执行第1行并在执行时检查变量,这是一个令人难以置信的学习工具。



调试器 - 维基百科,免费的百科全书 [ ^ ]

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html [ ^ ]

https://www.jetbrains.com/idea/help/debugging-your-first-java -application.html [ ^ ]

调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。

调试器中没有魔法,它没有找到错误,它只是帮助你至。当代码没有达到预期的效果时,你就会接近一个错误。
There is a tool that allow you to see what your code is doing, its name is debugger.
It is also a great learning tool because it show you reality and you can see which expectation match reality.

Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


这篇关于我是新编程的学习者。请任何人解释一下JAVA代码片段。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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