How an 'if (A && B)' statement is evaluated?

后端 未结 5 467
野性不改
野性不改 2020-12-14 18:47
if( (A) && (B) )
{
  //do something
}
else
  //do something else

The question is, would the statement immediately break to else if A was FA

5条回答
  •  一整个雨季
    2020-12-14 19:05

    Yes, it is called Short-circuit Evaluation.

    If the validity of the boolean statement can be assured after part of the statement, the rest is not evaluated.

    This is very important when some of the statements have side-effects.

提交回复
热议问题