<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">You can define an extension on interval types:<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">extension</span> <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">HalfOpenInterval</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> Bound: Strideable {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> by(n: </span>Bound<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span>Stride<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">) -&gt; </span>StrideTo<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&lt;</span>Bound<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&gt; {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">start</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">stride</span>(to: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">end</span>, by: n)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">extension</span> <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">ClosedInterval</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span> Bound: Strideable {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> by(n: </span>Bound<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span>Stride<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">) -&gt; </span>StrideThrough<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&lt;</span>Bound<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&gt; {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">start</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">stride</span>(through: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">end</span>, by: n)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-family: Helvetica; font-size: 12px;" class="">Which maybe gives you slightly more elegant usage:</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">for</span> lat <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">in</span> (<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">CGFloat</span>(-<span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">60</span>)...<span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">60</span>).<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">by</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">30</span>) {</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span>(lat)</div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">for</span> lat <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">in</span> (<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">CGFloat</span>(-<span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">60</span>)..&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">60</span>).<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">by</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">30</span>) {</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span>(lat)</div><div style="margin: 0px; line-height: normal;" class="">}</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div></div><div><blockquote type="cite" class=""><div class="">On 19 Dec 2015, at 18:59, Gavin Eadie via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">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:<div class=""><br class=""></div><div class=""><font face="Courier" class=""><span style="font-size: 11px;" class="">&nbsp; &nbsp; for lat in (CGFloat(-60.0)).stride(through: +60.0, by: 30.0) {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; path.moveToPoint(CGPointMake(-180.0, lat))<br class="">&nbsp; &nbsp; &nbsp; &nbsp; path.lineToPoint(CGPointMake(+180.0, lat))<br class="">&nbsp; &nbsp; }<br class=""><br class="">&nbsp; &nbsp; for lon in (CGFloat(-150.0)).stride(through: +150.0, by: 30.0) {<br class="">&nbsp; &nbsp; &nbsp; &nbsp; path.moveToPoint(CGPointMake(lon, +90.0))<br class="">&nbsp; &nbsp; &nbsp; &nbsp; path.lineToPoint(CGPointMake(lon, -90.0))<br class="">&nbsp; &nbsp; }<br class=""></span></font><br class=""></div><div class="">That seems a slightly cumbersome usage. &nbsp;Is there a better way to initialize the SequenceType I want to iterate over?</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=Lo8TP3b1oIn3yQXUt9zA1UCQfR-2BMBCuqnubTuDg47-2B2JrWct5LdmVtzlyLW-2FdFy-2BgksNk2B1nhv7HyAz0CWOkz3uQImvpZhn0tb9ulJe09H7KnMvvQYuNn1jvNDTuRxES-2FE9NCn3AlgkmyF9n8EHZrSTZEYMdrE-2F-2B-2FIkSBhtNgf0z6l-2FLBFGr3QUlmpEk6MrCUh8Xw1CAyWJiIZPEP4Gw2Oq4-2FEB-2BVfb9jsek6Esir8-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</div>
_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-dev<br class=""></div></blockquote></div><br class=""></div></body></html>