<div dir="ltr">> The proposed extension looks to me like is iterating both the suits and rank at the same time.<div>So, it looks like different things to different people, which doesn't bode well for its acceptance.</div><div><br></div><div><div>> The alternative now:</div></div><div>That's what zip is for:</div><div><br></div><div><div>var count = 0</div><div><br></div><div>for (x, y) in zip(ranks, suits) {</div><div> count += 1</div><div>}</div><div><br></div><div>count // 4</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 10, 2015 at 12:31 AM, J. Cheyo Jimenez via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div>The proposed extension looks to me like is iterating both the suits and rank at the same time. In that case I think is a great idea.</div><span class=""><div><br></div><div><span style="font-size:12.8px">var cards: [(Suit,Rank)] = []</span><br style="font-size:12.8px"><span style="font-size:12.8px">for x in suits, y in ranks {</span><br style="font-size:12.8px"><span style="font-size:12.8px"> cards.append((x,y))</span><br style="font-size:12.8px"><span style="font-size:12.8px">}</span></div></span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">What I am expecting:</span><br></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">x1, y1</span></div><div><span style="font-size:12.8px">x2, y2</span></div><div><span style="font-size:12.8px">x3, y3</span></div><div><span style="font-size:12.8px">etc</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">This reminds me that this is one of the ways I use the C-style for-loop. </span></div><div><span style="font-size:12.8px">The alternative now:</span></div><div><span style="font-size:12.8px"><br></span></div><div><span>for</span><span> (index, x) </span><span>in</span><span> </span><span>suits</span><span>.</span><span>enumerate</span><span>(){</span></div><div><span> </span><span>let</span><span> y = </span><span>ranks</span><span>[index]</span></div><div><span> </span><span>cards</span><span>.</span><span>append</span><span>((x,y))</span></div><div>
<p><span>}</span></p><p><br></p></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px"><br></span></div><div><br></div></div><div><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 9, 2015 at 12:00 PM, Chris Eidhof via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I think it could be really nice to extend the for-loop so that it can have multiple clauses. Much like in the if-let with multiple clauses, I could imagine a for-loop with multiple clauses:<br>
<br>
var cards: [(Suit,Rank)] = []<br>
for x in suits, y in ranks {<br>
cards.append((x,y))<br>
}<br>
<br>
This would be the same as writing:<br>
<br>
var cards: [(Suit,Rank)] = []<br>
for x in suits {<br>
for y in ranks {<br>
cards.append((x,y))}<br>
}<br>
}<br>
<br>
You could also do something like:<br>
<br>
for x in input1, y in (x..<end) {<br>
// Do something with (x,y)<br>
}<br>
<br>
In fact, once we would have that, we could combine both if-let and for, and make it more general, to end up with something like Haskell’s do-notation or C#’s LINQ. But that might be taking it too far...<br>
<br>
Chris<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div><br></div>
</div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=1p9Jer2O6jVE9KWvo-2B9iUaEyN8slp4IizyiLwsfp54My-2FOmYSOkcQ5dk522EyHx6qVgXi4dDOitIv9kmXRNmfLCvLbmZDc9aZ8X-2F-2By-2BZoc6-2Fk-2FYo9K5kWdfz3hvmyVemntW8xJ-2FmDcvqbQue-2F7vjXjNBPu22VO38EKanV9NB-2BzYIXwgv5lT3RLrs11EUVz40zhGSTyX7kMkWfEr3WoIAMVqEm1i2ZSX-2Fk-2BJosbxlHDo-3D" alt="" width="1" height="1" border="0" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;">
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div></div>