本文介绍了Java标签用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过java好文章,我发现这样的代码完美编译。
Somewhere going through java good articles, I found that such code compiles perfectly.
public int myMethod(){ www.google return 1; }说明 http: word将被视为标签, // www.google 作为评论
description says that http: word will be treated as label and //www.google as comment
我没有得到Java Label如何在循环外使用? 在什么情况下应该使用Java Label外部循环?
I am not getting how Java Label is useful outside loop? Under what situation Java Label outside loop should be used?
推荐答案以下是在Java中使用标签的一个好处:
Here is one benefit of using labels in Java:
block: { // some code if(condition) break block; // rest of code that won't be executed if condition is true }嵌套循环的另一种用法:
Another usage with nested-loops:
outterLoop: for(int i = 0; i < 10; i++) { while(condition) { // some code if(someConditon) break outterLoop; // break the for-loop if(anotherConditon) break; // break the while-loop // another code } // more code }或:
outterLoop: for(int i = 0; i < 10; i++) { while(condition) { // some code if(someConditon) continue outterLoop; // go to the next iteration of the for-loop if(anotherConditon) continue; // go to the next iteration of the while-loop // another code } // more code }更多推荐
Java标签用法
发布评论