<div dir="ltr">(As I said, I can live with `while`. I am simply presenting a potential point of confusion.) <div>You aren't evaluating the statements in the loop 'while' the condition isn't met. The first time that the condition isn't met, evaluation of the loop stops. I get that this is technically true for the `while` construct but I suggest that the only reason that it works there is that 'stopping the first time that the condition isn't met' *is* the construct. Here, we have a loop that we execute for each thing and we're tacking on/intermingling the `while` construct.</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 6, 2016 at 2:19 PM, Thorsten Seitz <span dir="ltr"><<a href="mailto:tseitz42@icloud.com" target="_blank">tseitz42@icloud.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> Am 06.06.2016 um 19:43 schrieb Tim Vermeulen via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>:<br>
><br>
> I also considered `until`, but it would be a bit confusing that `where` makes sure a condition is met, while `until` makes sure the condition isn’t met. I think `while` makes more sense because it corresponds to `break` in the same way that `where` corresponds to `continue`.<br>
<br>
</span>That's a good argument! The only drawback is that `while` and `where` look quite similar at a glance.<br>
<span class="HOEnZb"><font color="#888888"><br>
-Thorsten<br>
</font></span><span class="im HOEnZb"><br>
><br>
>> `while`, to me, actually reads like it should do what `where` does.<br>
><br>
> To me, `while` reads like it should stop the loop once the condition isn’t met, just like in a while loop.<br>
><br>
>> I hadn't thought about `while` in this regard but wouldn't `until` make more sense? `while`, to me, actually reads like it should do what `where` does. In any case, whether it is `while` or `where`, this seems like a reasonable feature in my opinion.<br>
>><br>
>> TJ<br>
>><br>
>> On Mon, Jun 6, 2016 at 5:15 AM, Tim Vermeulen via swift-evolution<<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>)>wrote:<br>
>>> 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>(mailto:<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>
</span><div class="HOEnZb"><div class="h5">> _______________________________________________<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>
</div></div></blockquote></div><br></div>