gpt4 book ai didi

java - Java 中的冒号有什么作用?

转载 作者:行者123 更新时间:2023-12-01 23:06:36 25 4
gpt4 key购买 nike

public void go(){
String o = "";
z:
for (int x = 0; x<3; x++) {
for (int y = 0; y<2;y++) {
if (x==1)
break;
if (x==2 && y==1)
break z;
o = o + x+y;
}
}

System.out.println(o);
}

最佳答案

它是label对于导演break (或 directed continue )。请参阅下面添加的评论:

public void go(){
String o = "";
z: // <=== Labels the loop that follows
for (int x = 0; x<3; x++) {
for (int y = 0; y<2;y++) {
if (x==1)
break; // <=== Not directed, only breaks the inner loop
if (x==2 && y==1)
break z; // <=== Directed break, breaks the loop labelled with `z`
o = o + x+y;
}
}

System.out.println(o);
}

关于java - Java 中的冒号有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22657783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com