iOS ● ○ ○ Swift 6

Kodebits Day 82: Stride By Value

Aug 26 2026
Practice loops with a short swift challenge.

What does this print?

let s1 = stride(
  from: 2, to: 10, by: 3
)
for i in s1 {
  print(i, terminator: " ")
}
print()
let s2 = stride(
  from: 12, through: 6, by: -2
)
for i in s2 {
  print(i, terminator: " ")
}


Try it in the online Swift Playground →

[spoiler title="Solution"]

Answer:

2 5 8
12 10 8 6

Explanation:

stride generates sequences with custom steps; to excludes end, through includes it.

[/spoiler]


Further Reading