Bird
0
0

Which of the following is the correct syntax to create a stride in Swift from 1 to 10 with step 3, excluding 10?

easy📝 Syntax Q3 of 15
Swift - Loops
Which of the following is the correct syntax to create a stride in Swift from 1 to 10 with step 3, excluding 10?
Astride(1, 10, 3)
Bstride(from: 1, through: 10, by: 3)
Cstride(from: 1, to: 10, by: 3)
Dstride(from: 1, to: 10, step: 3)
Step-by-Step Solution
Solution:
  1. Step 1: Recall stride syntax

    The correct syntax uses named parameters: from, to or through, and by.
  2. Step 2: Identify correct option

    stride(from: 1, to: 10, by: 3) uses stride(from: 1, to: 10, by: 3), which is correct syntax and excludes 10. stride(from: 1, through: 10, by: 3) includes 10. Options C and D have incorrect syntax.
  3. Final Answer:

    stride(from: 1, to: 10, by: 3) is correct syntax excluding 10 -> Option C
  4. Quick Check:

    Correct stride syntax with 'to' excludes end = A [OK]
Quick Trick: Use 'to' to exclude end, 'through' to include end in stride [OK]
Common Mistakes:
  • Using unnamed parameters or wrong parameter names
  • Confusing 'to' and 'through'
  • Using 'step' instead of 'by'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes