[swift-evolution] Feature proposal: Range operator with step

Vladimir.S svabox at gmail.com
Mon Apr 18 10:28:40 CDT 2016

On 15.04.2016 3:57, Hans Huck via swift-evolution wrote:
 > Anyway, why not just make it .step() then, like in Ruby?
 > Instead of a "by" keyword, I'd be happy with syntactic sugar in the form of
 > for i in p1..<p2 step x

As for 'step' word: It seems like for now IMO this is the best suggestion : 
very explicit, anyone knows what "step" means especially in context of 
loop, clear that "step" belongs to for-in construction(not to range itself).

for i in 0..<10 step 2 {

for i in 0..<10 step -2 {

for i in 0.1..<10.5 step 0.5 {

all are mapped to needed ranges/intervals under the hood
Do you want some custom Range-specific methods to provide steps for loop - 
no problems, use what you need. But don't force any of us to use 
(0..<10).striding(by:2) for myriads of simple loops in our code.

I want to see such constructions in our Swift. Who is with me ? :)

More information about the swift-evolution mailing list