Bird
0
0

Find the mistake in this Swift code snippet:

medium📝 Debug Q7 of 15
Swift - Loops
Find the mistake in this Swift code snippet:
let scores = [85, 90, 75, 60]
for score in scores where score > 80
    print(score)
}
AIncorrect use of <code>where</code> clause
BMissing opening brace after <code>for</code> loop
CVariable <code>score</code> is not declared
DArray <code>scores</code> is empty
Step-by-Step Solution
Solution:
  1. Step 1: Check loop syntax

    The for loop requires braces { } to enclose the loop body.
  2. Step 2: Identify missing brace

    The opening brace { after the for line is missing.
  3. Final Answer:

    Missing opening brace after for loop -> Option B
  4. Quick Check:

    Loops need braces to define body [OK]
Quick Trick: Always use braces {} to wrap for loop body [OK]
Common Mistakes:
  • Omitting braces for loop body
  • Misplacing where
  • Assuming variable not declared

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes