英文:
Checking 1st if condition and then 2nd
问题
以下是翻译好的部分:
在 for 循环中是否有一种方法可以进行检查,其中第一个循环仅检查 `abb.iscurrently()`,如果为真,则进入该块;而在第二个循环中,仅检查 `abb.islately()`,避免检查 `abb.iscurrently()`?以下是我的当前代码。
for (){if (abb.iscurrentlyy() || abb.islately()) {
if (reqFiles != null) {
for (int i = 0; i < reqFiles.length; i++) {
Future<ExecResult> lcukv = executor.submit(worker);
executionFutureException.add(lcukv);
}
}
} else { // 如果条件为假则执行。
}
英文:
Is there a way to put a check in for loop where 1st loop only checks if abb.iscurrently()
and if its true go inside the block and in 2nd loop only checks abb.islately()
avoid checking abb.iscurrently()
? My Current code.
for (){if (abb.iscurrentlyy() || abb.islately()) {
if (reqFiles != null) {
for (int i = 0; i < reqFiles.length; i++) {
Future<ExecResult> lcukv = executor.submit(worker);
executionFutureException.add(lcukv);
}
}
} else { // do if condition is false.
}
}
答案1
得分: 0
使用 Continue;
,来跳过循环中剩余的步骤。
英文:
Use Continue;
, to skip the rest of the steps in the loop.
答案2
得分: 0
我不确定为什么有人想要这样做,但这个逻辑应该有效。
boolean flag = true;
for () {
(flag && if (abb.iscurrentlyy()) || abb.islately()) {
flag = false; // 这将每次执行
if (reqFiles != null) {
for (int i = 0; i < reqFiles.length; i++) {
Future<ExecResult> lcukv = executor.submit(worker);
executionFutureException.add(lcukv);
}
}
} else { // 如果条件为false,则执行。
}
}
英文:
I am not sure why someone wants to do that, But this logic should work.
boolean flag = true;
for (){(flag && if (abb.iscurrentlyy()) || abb.islately()) {
flag = false; // this will execute everytime
if (reqFiles != null) {
for (int i = 0; i < reqFiles.length; i++) {
Future<ExecResult> lcukv = executor.submit(worker);
executionFutureException.add(lcukv);
}
}
}else{ // do if condition is false.
}}
专注分享java语言的经验与见解,让所有开发者获益!
评论