Java标签用法

编程入门 行业动态 更新时间:2024-10-23 10:31:57
本文介绍了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标签用法

本文发布于:2023-11-13 00:53:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582961.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标签   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!