Recall & Review
beginner
What does the logical AND operator (&&) do in Swift?
The logical AND operator (&&) returns true only if both conditions on its sides are true. If either side is false, the whole expression is false.
Click to reveal answer
beginner
Explain the logical OR operator (||) in Swift.
The logical OR operator (||) returns true if at least one of the conditions is true. It returns false only if both conditions are false.
Click to reveal answer
beginner
What does the logical NOT operator (!) do in Swift?
The logical NOT operator (!) reverses the value of a Boolean. If the value is true, it becomes false; if false, it becomes true.
Click to reveal answer
intermediate
How would you combine multiple logical operators in Swift?
You can combine multiple logical operators by using parentheses to group conditions and control the order of evaluation, just like in math.
Click to reveal answer
intermediate
What is short-circuit evaluation in logical operators?
Short-circuit evaluation means Swift stops checking conditions as soon as the result is known. For example, in AND (&&), if the first condition is false, it won’t check the second.
Click to reveal answer
What is the result of true && false in Swift?
✗ Incorrect
The AND operator returns true only if both sides are true. Here, one side is false, so the result is false.
Which operator returns true if at least one condition is true?
✗ Incorrect
The OR operator (||) returns true if any condition is true.
What does !true evaluate to in Swift?
✗ Incorrect
The NOT operator (!) reverses the Boolean value, so !true is false.
In the expression (false || true) && false, what is the result?
✗ Incorrect
false || true is true, but true && false is false.
What happens in short-circuit evaluation with the expression false && someFunction()?
✗ Incorrect
Because the first condition is false, Swift does not call someFunction() since the whole AND expression cannot be true.
Describe how the logical AND (&&), OR (||), and NOT (!) operators work in Swift.
Think about true and false combinations.
You got /3 concepts.
Explain what short-circuit evaluation means and why it is useful in Swift logical operations.
Imagine checking conditions like a checklist that stops early.
You got /3 concepts.