[swift-dev] C-style For Loops

Gavin Eadie gavin at umich.edu
Sat Dec 19 12:59:44 CST 2015


With C-style for loops to be removed from the language to general acclaim (including mine), is the following the best way to perform the required looping:

    for lat in (CGFloat(-60.0)).stride(through: +60.0, by: 30.0) {
        path.moveToPoint(CGPointMake(-180.0, lat))
        path.lineToPoint(CGPointMake(+180.0, lat))
    }

    for lon in (CGFloat(-150.0)).stride(through: +150.0, by: 30.0) {
        path.moveToPoint(CGPointMake(lon, +90.0))
        path.lineToPoint(CGPointMake(lon, -90.0))
    }

That seems a slightly cumbersome usage.  Is there a better way to initialize the SequenceType I want to iterate over?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20151219/7d243593/attachment.html>


More information about the swift-dev mailing list