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

Jacob Bandes-Storch jtbandes at gmail.com
Wed Jun 8 13:51:17 CDT 2016

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160608/195e6574/attachment.html>

More information about the swift-evolution mailing list