[swift-dev] C-style For Loops

Dave Abrahams dabrahams at apple.com
Fri Feb 19 20:54:58 CST 2016


on Sat Dec 19 2015, Wallacy <swift-dev-AT-swift.org> wrote:

>>
>> Why?
>>
>
> Because this works:
>
> var rangeA = -150.0..<150
> for lat in rangeA.by(30) {
>     print(lat)
> }
>
> And this not:
>
> var rangeC = -150..<150
> for lat in rangeC.by(30) { // Error - Value of type 'Range<Int>' has no
> member 'by'
>     print(lat)
> }
>
> I think this is expected to work, or not?

Fair enough; that makes sense.

> If you make a extension for "Range" will work of course.
>
>> I don't understand most of what you're saying here, or why you're saying
>> it.  The extensions as shown in Donnacha's post work for me.
>>
>>
>>
> Not a big deal, just saying I think weird call "startIndex" and "endIndex"
> on "Range", because on (HalfOpen|Close)Interval are only "start" and "end".

Range is a collection, so it has to have startIndex and endIndex.
Interval does not necessarily have anything to do with indices.

> Also is weird the existence of the 3 types for basically the same
> purpose.

We're missing the generics features that would allow them to be unified.

-- 
-Dave



More information about the swift-dev mailing list