English 中文(简体)
检查“ 如果” 语句中的所有条件? [重复]
原标题:Check all conditions in an "if" statement? [duplicate]
This question already has answers here:
Closed 11 years ago.

Possible Duplicate:
Why do we usually use || not |, what is the difference?

示例:

if(a && b && d)
{
...
}

我需要找出语言是否支持检查语句中的所有条件, 即使“ b” 失败。 这个概念叫什么?

问题回答

不, Java 和 C++ 都不会评估 < code> d 。 这是 < a href=" http://en.wikipedia.org/wiki/Short- section_ value" @em>short- section valuation 。

否, 二进制逻辑运算符是短路。 他们从左向右评估其操作符。 如果其中一位操作符评价表达式为假, 那么其他操作符就不会被评估 。

站点二进制线( amp; & amp;) 和 {} 是 < a href=" http:// en.wikipedia. org/ wiki/Short- second_ valuation" rel= "nofollow" >short- secreed 。 如果您想要迫使双方评估, 使用 & amp; 或\\\\\ 而不是 & amp;& 和\\\\ 。 例如 。

public class StackOverflow {

   static boolean false1() {
      System.out.println("In false1");
      return false;
   }

   static boolean false2() {
      System.out.println("In false2");
      return false;
   }

   public static void main(String[] args) {
      System.out.println("shortcircuit");
      boolean b = false1() && false2();

      System.out.println("full evaluation");
      b = false1() & false2();
   }
}




相关问题
Detect months with 31 days

Is there an analogous form of the following code: if(month == 4,6,9,11) { do something; } Or must it be: if(month == 4 || month == 6 etc...) { do something; } I am trying to write an if ...

&& (AND) and || (OR) in IF statements

I have the following code: if(!partialHits.get(req_nr).containsKey(z) || partialHits.get(req_nr).get(z) < tmpmap.get(z)){ partialHits.get(z).put(z, tmpmap.get(z)); } where partialHits ...

If / else order sequence issue

I have the following set up, a ddl (ddlProd, radBuyer) and autocomplete text box (txtProdAC, radProd) that when populated and their respective radio buttons are selected, a grid view of the data is ...

PHP if or statement not working

We are trying to use the below piece of code if (($_GET[ 1 ] != "1") || ($_GET[ 1 ] != "2")) { When we try this no matter what value the variable has it will evaluate as true even when data is ...

C++ String manipulation - if stament

I have the following code that works correctly. However after I add an else statement anything always evaluates to else wgetstr(inputWin, ch); //get line and store in ch variable str = ch; ...

Are one-line if / for -statements good Python style?

Every so often on here I see someone s code and what looks to be a one-liner , that being a one line statement that performs in the standard way a traditional if statement or for loop works. I ...

Which is faster - if..else or Select..case?

I have three condition to compare. Which one is more faster between the following two? Please point me out. Thanks all! If var = 1 then Command for updating database ElseIf var = 2 then ...

热门标签