Bird
0
0

Which of the following is the correct syntax for using a where clause in a Swift for-in loop?

easy📝 Syntax Q12 of 15
Swift - Loops
Which of the following is the correct syntax for using a where clause in a Swift for-in loop?
Afor item where item.isActive in items { print(item) }
Bfor item in items where item.isActive { print(item) }
Cfor item in items if item.isActive { print(item) }
Dfor item in items; where item.isActive { print(item) }
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct for-in where syntax

    The correct syntax places where after the sequence: for variable in sequence where condition.
  2. Step 2: Check each option

    Only for item in items where item.isActive { print(item) } matches the correct syntax. The other options have misplaced or incorrect keywords: where before in, if instead of where, or a semicolon before where.
  3. Final Answer:

    for item in items where item.isActive { print(item) } -> Option B
  4. Quick Check:

    Correct where syntax [OK]
Quick Trick: Put where right after in sequence [OK]
Common Mistakes:
  • Placing where before in
  • Using if instead of where
  • Adding semicolon before where

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes