Bird
0
0

What does a for-in loop do when used with a collection like an array in Swift?

easy📝 Conceptual Q1 of 15
Swift - Loops
What does a for-in loop do when used with a collection like an array in Swift?
AIt sorts the collection automatically.
BIt creates a new collection with the same items.
CIt goes through each item in the collection one by one.
DIt removes items from the collection.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of a for-in loop

    A for-in loop is designed to repeat actions for each item in a collection, like an array.
  2. Step 2: Identify what happens during iteration

    During each loop, the code accesses one item at a time from the collection in order.
  3. Final Answer:

    It goes through each item in the collection one by one. -> Option C
  4. Quick Check:

    for-in loop purpose = iterate items [OK]
Quick Trick: For-in loops visit each item in order [OK]
Common Mistakes:
  • Thinking it modifies the collection
  • Confusing iteration with sorting
  • Assuming it creates a new collection

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes