gpt4 book ai didi

java - 是否可以退出 if 语句并返回到内部 for 循环?

转载 作者:行者123 更新时间:2023-11-29 09:39:36 25 4
gpt4 key购买 nike

是否有命令退出内部 for 循环内的 if 语句并让它仅通过该内部 for 循环?

例如:

for (int i = 0; i < blah.length; i++) {
blh = scan.nextDouble();
blah[i] = blh;

if(scores[i] < MIN || scores[i] > MAX_SCORE) {
errFlag = true;
System.out.println("ERROR: Enter numbers in the range of " +
MIN + "-" + MAX_SCORE + "!");
System.out.print("ERROR: Enter all " + numStudents + " scores again: ");
errFlag = false;
}
}

最佳答案

你可以使用标签 block

FOUND: {
for(Type mt: TypeList)
if(condtion(mt))
break FOUND;
// not found code here
}

根据 Java Language Specification 14.7

A labeled statement is executed by executing the immediately contained Statement. If the statement is labeled by an Identifier and the contained Statement completes abruptly because of a break with the same Identifier, then the labeled statement completes normally. In all other cases of abrupt completion of the Statement, the labeled statement completes abruptly for the same reason

关于java - 是否可以退出 if 语句并返回到内部 for 循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14392352/

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