Recall & Review
beginner
What is short-circuiting in conditions?
Short-circuiting means the program stops checking conditions as soon as the result is known. For example, in an AND condition, if the first part is false, it won't check the second part because the whole condition is false.
Click to reveal answer
beginner
Why is short-circuiting useful in blockchain smart contracts?
It saves gas (cost) by not running unnecessary checks. This makes smart contracts cheaper and faster to run.
Click to reveal answer
beginner
In the expression `A && B`, when is B NOT evaluated?
B is not evaluated if A is false, because the whole AND condition will be false regardless of B.
Click to reveal answer
beginner
In the expression `A || B`, when is B NOT evaluated?
B is not evaluated if A is true, because the whole OR condition will be true regardless of B.
Click to reveal answer
intermediate
Give an example of short-circuiting preventing an error in a smart contract condition.
If you check `user != address(0) && balance[user] > 0`, the second part runs only if `user` is not zero address. This avoids errors from checking balance of a zero address.
Click to reveal answer
In a condition `A && B`, if A is false, what happens?
✗ Incorrect
In AND conditions, if the first part is false, the whole condition is false, so the second part is skipped.
Why does short-circuiting save gas in blockchain smart contracts?
✗ Incorrect
Skipping checks means less computation, which costs less gas.
In `A || B`, when is B evaluated?
✗ Incorrect
In OR conditions, if A is true, the whole condition is true, so B is skipped.
What can short-circuiting help prevent in smart contracts?
✗ Incorrect
By skipping checks that could cause errors, short-circuiting helps avoid runtime errors.
Which operator uses short-circuiting to skip evaluation if the first condition is true?
✗ Incorrect
OR skips the second condition if the first is true.
Explain short-circuiting in conditions and why it matters in blockchain smart contracts.
Think about how skipping checks can save cost and avoid mistakes.
You got /4 concepts.
Describe a real-life example where short-circuiting prevents an error in a smart contract condition.
Consider checking if an address is zero before accessing its balance.
You got /3 concepts.