Bird
0
0

Which of the following is the correct syntax to create a stride in Swift that counts down from 10 to 2 by steps of 2, including 2?

easy📝 Syntax Q12 of 15
Swift - Loops
Which of the following is the correct syntax to create a stride in Swift that counts down from 10 to 2 by steps of 2, including 2?
Astride(from: 10, through: 2, by: -2)
Bstride(from: 10, to: 2, by: -2)
Cstride(from: 2, through: 10, by: 2)
Dstride(from: 2, to: 10, by: 2)
Step-by-Step Solution
Solution:
  1. Step 1: Identify counting down with inclusion

    Counting down from 10 to 2 means the step is negative (-2). Including 2 means using through.
  2. Step 2: Match syntax to requirements

    Only stride(from: 10, through: 2, by: -2) matches counting down with inclusion of 2.
  3. Final Answer:

    stride(from: 10, through: 2, by: -2) -> Option A
  4. Quick Check:

    Use 'through' to include end, negative step for countdown [OK]
Quick Trick: Use 'through' to include end; negative step for countdown [OK]
Common Mistakes:
  • Using 'to' instead of 'through' when including the end
  • Using positive step when counting down
  • Swapping start and end values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes