Practice question · True or false
Short-circuit evaluation of a AND b is what makes if x != 0 and 10/x > 1 safe.
Hints
- What happens to the division when x is zero?
- A false left side settles the expression.
Show the answer
True
Why
True. A false left operand fixes the whole conjunction as false, so the right side is never evaluated and the division never happens. It also means AND is not commutative once either side can fault, swapping the operands here crashes on exactly the input the guard was written for.
Practise Conditionals and Boolean Logic
The app has 7 more questions on this lesson, and keeps your place in the course. Mathematics I is free to start.