Bird
0
0

Find the error in this Swift code:

medium📝 Debug Q6 of 15
Swift - Operators and Expressions
Find the error in this Swift code:
let isSunny = true
if isSunny & true {
print("Go outside")
}
AUse && instead of & for logical AND
BUse || instead of &
CMissing parentheses around condition
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Identify operator usage

    The single & is a bitwise AND, not logical AND in Swift.
  2. Step 2: Correct operator for Boolean logic

    Logical AND requires && to combine Boolean conditions.
  3. Final Answer:

    Use && instead of & for logical AND -> Option A
  4. Quick Check:

    Logical AND uses &&, not & [OK]
Quick Trick: Use && for logical AND, & is bitwise [OK]
Common Mistakes:
  • Using & instead of &&
  • Assuming & works for Booleans
  • Missing operator error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes