Bird
0
0

Identify the error in this Swift code snippet:

medium📝 Debug Q14 of 15
Swift - Operators and Expressions
Identify the error in this Swift code snippet:
let x = true
let y = false
if x || && y {
    print("Yes")
}
AMissing parentheses around conditions
Bprint statement syntax error
CVariables x and y are not Boolean
DIncorrect use of logical operators together
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the if condition syntax

    The condition uses 'x || && y' which combines OR (||) and AND (&&) operators without a proper operand between them.
  2. Step 2: Identify the logical operator misuse

    Logical operators must connect two Boolean expressions. Here, '|| &&' is invalid syntax.
  3. Final Answer:

    Incorrect use of logical operators together -> Option D
  4. Quick Check:

    Operators must connect expressions properly [OK]
Quick Trick: Operators need operands on both sides [OK]
Common Mistakes:
  • Writing two operators without a condition between
  • Assuming parentheses fix operator misuse
  • Confusing variable types with operator errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes