Returns a sequence from a starting value toward, and possibly including, an end value, stepping by the specified amount.
SDK
- Xcode 8.0+
Framework
- Swift Standard Library
Declaration
Parameters
start
The starting value to use for the sequence. If the sequence contains any values, the first one is
start
.end
An end value to limit the sequence.
end
is an element of the resulting sequence if and only if it can be produced fromstart
using steps ofstride
.stride
The amount to step by with each iteration. A positive
stride
iterates upward; a negativestride
iterates downward.
Return Value
A sequence from start
toward, and possibly including, end
. Each value in the sequence is separated by stride
.
Discussion
You can use this function to stride over values of any type that conforms to the Strideable
protocol, such as integers or floating-point types. Starting with start
, each successive value of the sequence adds stride
until the next value would be beyond end
.
You can use stride(from:
to create a sequence that strides upward or downward. Pass a negative value as stride
to create a sequence from a higher start to a lower end:
The value you pass as end
is not guaranteed to be included in the sequence. If stepping from start
by stride
does not produce end
, the last value in the sequence will be one step before going beyond end
.
If you pass a value as stride
that moves away from end
, the sequence contains no values.