Bird
0
0

Given the async sequence numbers that yields 1, 2, 3, what will this code print?

medium📝 Predict Output Q13 of 15
iOS Swift - Concurrency
Given the async sequence numbers that yields 1, 2, 3, what will this code print?
for await num in numbers {
  print(num * 2)
}
A2 4 6
B1 2 3
C0 2 4
DError: Cannot multiply async sequence
Step-by-Step Solution
Solution:
  1. Step 1: Understand the async sequence values

    The sequence yields 1, 2, and 3 asynchronously.
  2. Step 2: Calculate output inside loop

    Each number is multiplied by 2 and printed: 2, 4, 6.
  3. Final Answer:

    2 4 6 -> Option A
  4. Quick Check:

    Multiply each yielded value by 2 [OK]
Quick Trick: Multiply each async value inside the loop [OK]
Common Mistakes:
  • Printing original values without multiplication
  • Expecting synchronous output order
  • Thinking async sequences cause errors here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes