[swift-evolution] Add a while clause to for loops

Xiaodi Wu xiaodi.wu at gmail.com
Wed Jun 8 13:52:48 CDT 2016

On Wed, Jun 8, 2016 at 1:51 PM, Jacob Bandes-Storch <jtbandes at gmail.com>

> On Wed, Jun 8, 2016 at 1:38 AM, Haravikk via swift-evolution <
> swift-evolution at swift.org> wrote:
>> I’m not sure I agree that this is confusing, a little extra to learn for
>> new programmers perhaps but I think it’s fairly intuitive:
>> while let value = foo.next() where someCondition(value) { … }
>> This reads to me as “repeat the following block until this fails to be
>> true”, the conditional binding in this case fails to be true if
>> someCondition(value) isn’t true, so the loop ends. I think the key thing
>> here is that the where clause is for the conditional binding and not the
>> loop itself, so in this respect it behaves exactly like an if or guard
>> statement.
> So, I think it might be much clearer if, similarly to how there's a
> discussion about unifying "where" vs. "comma" conditions in guard/if, we
> could do the same here.

>     while let value = foo.next(), let something = value.property,
> something == 4 { ... }
> (Apologies if this has been said; I haven't followed the whole thread
> closely.)

That's actually also a part of what's proposed in SE-0099.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160608/faa67cb7/attachment.html>

More information about the swift-evolution mailing list