检查第一个条件,然后第二个。

huangapple 未分类评论46阅读模式
英文:

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 &amp;&amp; if (abb.iscurrentlyy()) || abb.islately()) {
    flag = false; // this will execute everytime
    if (reqFiles != null) {

        for (int i = 0; i &lt; reqFiles.length; i++) {

            Future&lt;ExecResult&gt; lcukv = executor.submit(worker);
            executionFutureException.add(lcukv);
        }
    }

}else{ // do if condition is false.
}}

huangapple
  • 本文由 发表于 2020年7月26日 09:56:53
  • 转载请务必保留本文链接:https://java.coder-hub.com/63095371.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定