Member-only story
Advanced Swift: Stride
Learn about stride in the Swift Programming Language
Imagine you’re walking down a staircase, but instead of taking every single step, you decide to take one step, skip two, and repeat. You control the distance between steps. In Swift, stride is your tool for creating controlled, custom steps over a range of values. Whether you’re iterating through numbers, creating animations, or building charts, stride gives you flexibility and precision.
What Is stride?
The stride(from:to:by:) and stride(from:through:by:) functions in Swift generate a sequence of numbers. We decide the parameters:
from: The starting value of the sequence.to: The upper bound the sequence stops before reaching (exclusive).through: The upper bound the sequence includes (inclusive).by: The step value, indicating how much to increment or decrement between values.
Counting Up (Exclusive) Example:
Output:
- 1
- 3
- 5










