Bird
0
0

What does the where clause do in a for-in loop in Swift?

easy📝 Conceptual Q11 of 15
Swift - Loops
What does the where clause do in a for-in loop in Swift?
AIt repeats the loop twice for each item.
BIt changes the type of the loop variable.
CIt filters items so the loop runs only on those that meet the condition.
DIt stops the loop after the first item.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of where in a loop

    The where clause adds a condition to filter items during iteration.
  2. Step 2: Effect on loop execution

    Only items that satisfy the where condition are processed in the loop.
  3. Final Answer:

    It filters items so the loop runs only on those that meet the condition. -> Option C
  4. Quick Check:

    where filters loop items [OK]
Quick Trick: Remember: where filters items in the loop [OK]
Common Mistakes:
  • Thinking where changes variable type
  • Assuming it repeats the loop multiple times per item
  • Believing it stops the loop early

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes