<div dir="ltr">I brought up this suggestion in December:   <a href="http://thread.gmane.org/gmane.comp.lang.swift.evolution/1759" target="_blank">http://thread.gmane.org/gmane.comp.lang.swift.evolution/1759</a><br><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Jacob<br></div></div></div></div>
<br><div class="gmail_quote">On Mon, Jun 6, 2016 at 3:15 AM, Tim Vermeulen via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">We can already use a where clause in a for loop like this:<br>
<br>
for element in array where someCondition(element) {<br>
    // …<br>
}<br>
<br>
which basically acts like<br>
<br>
for element in array {<br>
    guard someCondition(element) else { continue }<br>
    // …<br>
}<br>
<br>
Sometimes you want to break out of the loop when the condition isn’t met instead. I propose a while clause:<br>
<br>
for element in array while someCondition(element) {<br>
    // …<br>
}<br>
<br>
which would be syntactic sugar for<br>
<br>
for element in array {<br>
    guard someCondition(element) else { break }<br>
    …<br>
}<br>
<br>
I can see this particularly being useful if we have a sorted array and we already know that once the condition isn’t met, it won’t be met either for subsequent elements. Another use case could be an infinite sequence that we want to cut off somewhere (which is simply not possible using a where clause).<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>
</blockquote></div><br></div></div>