gpt4 book ai didi

java - 没有循环结构的继续命令

转载 作者:行者123 更新时间:2023-11-30 08:18:38 25 4
gpt4 key购买 nike

try{
if(condition A || condition B || condition C)
do something
}catch (IndexOutOfBoundsException e){
//Equivalent command to continue
}

假设我在条件 B 中有一个异常,我希望它忽略它并检查是否满足条件 C。如果它不是循环结构,因此不能使用 continue 命令,我该怎么做?

最佳答案

你可以这样做。

假设您对它们的所有条件执行相同的操作。 (T是你的数据类型)

    List<T> conditions = ArrayList<>();
boolean flag = false;
for(T condition : conditions) {
try{
if(!condition)
flag = false;
}catch (IndexOutOfBoundsException e){
//Equivalent command to continue
}
if(flag) {
//do something
}
}

关于java - 没有循环结构的继续命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27381938/

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