Bird
0
0

Which collection types can you use directly in a Swift for-in loop?

easy📝 Conceptual Q2 of 15
Swift - Loops
Which collection types can you use directly in a Swift for-in loop?
AArrays, dictionaries, and sets
BOnly arrays
COnly dictionaries
DOnly sets
Step-by-Step Solution
Solution:
  1. Step 1: Recall Swift collection types

    Swift has arrays, dictionaries, and sets as common collections.
  2. Step 2: Check for-in loop compatibility

    All these collections conform to the Sequence protocol, so they can be used in for-in loops.
  3. Final Answer:

    Arrays, dictionaries, and sets -> Option A
  4. Quick Check:

    for-in loop collections = arrays, dictionaries, sets [OK]
Quick Trick: For-in works with any sequence collection [OK]
Common Mistakes:
  • Thinking only arrays work
  • Ignoring sets as iterable
  • Confusing dictionaries with non-collections

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes