No, he does not evaluate the expression after studying that the answer will be NO . This is called short-circuited, and it is an important part of evaluating Boolean expressions in C, C ++, Objective-C, and other languages ββwith similar syntax. Conditions are evaluated from left to right, which makes the assessment scheme predictable.
The same rule applies to the || : as soon as the code knows that the value is YES , the evaluation stops.
A short circuit protects against an invalid score in a single compound expression, rather than choosing an if . For instance,
if (index >= 0 && index < Length && array[index] == 42)
would lead to undefined behavior if it were not intended to be a short circuit. But since the evaluation skips the evaluation of array[index] when index invalid, the above expression is legal.
source share