Why is order of expressions in if statement important

后端 未结 9 2082
无人共我
无人共我 2021-01-05 03:01

Suppose I have an IF condition :

if (A || B) 
    ∧
    |
    |
   left
{ 
   // do something  
}

Now suppose that A

9条回答
  •  佛祖请我去吃肉
    2021-01-05 03:39

    As per javadoc

    The && and || operators perform Conditional-AND and Conditional-OR operations on two boolean expressions. These operators exhibit "short-circuiting" behavior, which means that the second operand is evaluated only if needed

    So, if true statement comes first in the order, it short-circuits the second operand at runtime.

提交回复
热议问题