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

David Knothe dknothe314 at me.com
Wed Mar 23 16:40:09 CDT 2016


Hi,

I am new to Swift mailing list so I don’t know if this topic has already been discussed.

I like Swift's range operators ..< and …
What I am missing though is an easy operator to create a range with a specified step. Currently, if you would want to iterate over some odd numbers, you had to write:
for i in 1.stride(through: 7, by: 2) { … }
What I think would be simpler and more convenient would be something like the following:
for i in 1 … 7 step 2 { … } . Another option would be  for i in 1 … 7; 2 { … }
The keyword ‚step‘ in this context clearly corresponds to the step of the range to create or to iterate over.

Essentially this is a syntactic sugar that makes it easy to create ranges with a step ≠ 1. What do you think?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160323/731d3c1e/attachment.html>


More information about the swift-evolution mailing list