Recall & Review
beginner
What is the Bool type in Swift?
Bool is a data type in Swift that can hold only two values: true or false. It is used to represent logical conditions.
Click to reveal answer
beginner
What does the logical AND operator (&&) do?
The logical AND operator (&&) returns true only if both conditions on its sides are true. Otherwise, it returns false.
Click to reveal answer
beginner
What is the result of
true || false in Swift?The logical OR operator (||) returns true if at least one of the conditions is true. So,
true || false evaluates to true.Click to reveal answer
beginner
How does the logical NOT operator (!) work?
The logical NOT operator (!) reverses the value of a Bool. If the value is true, it becomes false, and vice versa.
Click to reveal answer
beginner
What will be the output of this Swift code?<br><pre>let a = true
let b = false
print(a && b)</pre>The output will be false because the AND operator (&&) requires both values to be true, but here
b is false.Click to reveal answer
Which of these is a valid Bool value in Swift?
✗ Incorrect
Only
true and false are valid Bool values in Swift.What does the expression
false || false evaluate to?✗ Incorrect
The OR operator (||) returns true if at least one side is true. Here both are false, so result is false.
What is the result of
!true in Swift?✗ Incorrect
The NOT operator (!) reverses the Bool value, so
!true is false.Which operator checks if both conditions are true?
✗ Incorrect
The AND operator (&&) returns true only if both conditions are true.
What will
print(true && false) output?✗ Incorrect
AND operator requires both true, here one is false, so output is false.
Explain the Bool type and how logical operators work in Swift.
Think about true/false values and how you combine or reverse them.
You got /4 concepts.
Describe a real-life example where you might use logical AND and OR operators.
Think about everyday decisions with multiple conditions.
You got /4 concepts.