Bird
0
0

Which of the following is the correct syntax to iterate over an async sequence named stream?

easy📝 Syntax Q12 of 15
iOS Swift - Concurrency
Which of the following is the correct syntax to iterate over an async sequence named stream?
Afor value in stream.await { print(value) }
Bfor value in await stream { print(value) }
Cawait for value in stream { print(value) }
Dfor await value in stream { print(value) }
Step-by-Step Solution
Solution:
  1. Step 1: Recall async sequence iteration syntax

    Swift uses for await to loop over async sequences.
  2. Step 2: Match syntax with options

    Only for await value in stream { print(value) } uses for await value in stream, which is correct syntax.
  3. Final Answer:

    for await value in stream { print(value) } -> Option D
  4. Quick Check:

    Use 'for await' to loop async sequences [OK]
Quick Trick: Use 'for await' before the loop variable [OK]
Common Mistakes:
  • Placing 'await' after 'for' incorrectly
  • Using 'await' inside the loop variable
  • Trying to access '.await' property on sequence

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes