Bird
0
0

What will be printed by this Swift code?

medium📝 Predict Output Q5 of 15
Swift - Collections
What will be printed by this Swift code?
let numbers = [10, 20, 30]
for (i, num) in numbers.enumerated() {
    print(i * num)
}
A0 10 20
B0 20 60
C10 20 30
D10 40 90
Step-by-Step Solution
Solution:
  1. Step 1: Calculate each iteration's output

    Index and element pairs: (0,10), (1,20), (2,30). Multiply index * element: 0*10=0, 1*20=20, 2*30=60.
  2. Step 2: Match calculated values with options

    0 20 60 matches the sequence 0, 20, 60 exactly.
  3. Final Answer:

    0 20 60 -> Option B
  4. Quick Check:

    Multiply index by element for output [OK]
Quick Trick: Multiply index and element inside loop for output [OK]
Common Mistakes:
  • Using element only
  • Using index only
  • Adding instead of multiplying

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes