Bird
0
0

Identify the error in the following Swift code snippet:

medium📝 Debug Q14 of 15
Swift - Collections
Identify the error in the following Swift code snippet:
let numbers = [10, 20, 30]
for index, value in numbers.enumerated {
    print(index, value)
}
Aprint statement syntax is invalid.
BIncorrect variable names in the for loop.
CArray declaration syntax is wrong.
DMissing parentheses after enumerated() method call.
Step-by-Step Solution
Solution:
  1. Step 1: Check method call syntax

    The method enumerated must be called with parentheses: enumerated().
  2. Step 2: Verify other parts of the code

    Variable names and array declaration are correct; print syntax is valid.
  3. Final Answer:

    Missing parentheses after enumerated() method call. -> Option D
  4. Quick Check:

    enumerated() needs () [OK]
Quick Trick: Always add () after enumerated [OK]
Common Mistakes:
  • Forgetting parentheses after enumerated
  • Swapping index and value order
  • Using wrong print syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes