#80: stride in Swift

stride is the right tool when you want a loop with a custom step.

for value in stride(from: 0, through: 10, by: 2) {
    print(value)
}

Use through when the end value is inclusive and to when it is exclusive.

It is a small API, but much clearer than manually updating counters inside a while loop.


I'm also on Twitter and GitHub.

Subscribe via RSS.