Bird
0
0

What will be printed by this Swift code?

medium📝 Predict Output Q5 of 15
Swift - Loops
What will be printed by this Swift code?
for i in stride(from: 5, through: 15, by: 5) {
    print(i)
}
A5 10
B5 15
C5 10 15
D10 15
Step-by-Step Solution
Solution:
  1. Step 1: Analyze stride parameters

    Start at 5, go through 15 (including 15), step by 5.
  2. Step 2: List values printed

    Values: 5, 10, 15. Since 'through' includes 15, it is printed.
  3. Final Answer:

    5 10 15 -> Option C
  4. Quick Check:

    Stride 'through' includes end value = B [OK]
Quick Trick: Use 'through' to include the last value in stride [OK]
Common Mistakes:
  • Using 'to' and expecting end included
  • Skipping the last value
  • Incorrect step size

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes