<div dir="ltr"><div>What you described Felix seems to be different to what was proposed, also I think (as you suggest) that `else` is unclear for what you describe.</div><div><br></div><div>To clarify, is what you&#39;re suggesting logically equivalent to this?</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)"><span style="color:rgb(187,44,162)">if</span><span style="color:rgb(34,34,34)"> </span><span style="color:rgb(187,44,162)">let</span><span style="color:rgb(34,34,34)"> found = [</span><span style="color:rgb(39,42,216)">1</span><span style="color:rgb(34,34,34)">,</span><span style="color:rgb(39,42,216)">2</span><span style="color:rgb(34,34,34)">,</span><span style="color:rgb(39,42,216)">3</span><span style="color:rgb(34,34,34)">,</span><span style="color:rgb(39,42,216)">4</span><span style="color:rgb(34,34,34)">].</span><span style="color:rgb(49,89,93)">find(</span><span style="color:rgb(34,34,34)">{ </span><span style="color:rgb(34,34,34)">$0 == </span><span style="color:rgb(39,42,216)">3 </span><span style="color:rgb(34,34,34)">}) {</span></p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(209,47,27)"><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(61,29,129)">print</span><span style="color:rgb(0,0,0)">(</span>&quot;exited early (<span style="color:rgb(0,0,0)">\</span>(<span style="color:rgb(0,0,0)">found</span>))&quot;<span style="color:rgb(0,0,0)">)</span></p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(61,29,129)"><span style="color:rgb(0,0,0)"><br></span></p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)"><span style="color:rgb(187,44,162)">extension</span><span style="color:rgb(0,0,0)"> </span>SequenceType<span style="color:rgb(0,0,0)"> {</span></p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:rgb(187,44,162)">func</span> find(</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">        <span style="color:rgb(187,44,162)">@noescape</span> each: Generator.Element <span style="color:rgb(187,44,162)">throws</span> -&gt; <span style="color:rgb(112,61,170)">Bool</span></p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)"><span style="color:rgb(0,0,0)">    ) </span><span style="color:rgb(187,44,162)">rethrows</span><span style="color:rgb(0,0,0)"> -&gt; </span>Generator<span style="color:rgb(0,0,0)">.</span>Element<span style="color:rgb(0,0,0)">? {</span></p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">        <span style="color:rgb(187,44,162)">for</span> element <span style="color:rgb(187,44,162)">in</span> <span style="color:rgb(187,44,162)">self</span> {</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">            <span style="color:rgb(187,44,162)">if</span> <span style="color:rgb(187,44,162)">try</span> each(element) == <span style="color:rgb(187,44,162)">false</span> {</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">                <span style="color:rgb(187,44,162)">return</span> element</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">            }</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">        }</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">        <span style="color:rgb(187,44,162)">return</span> <span style="color:rgb(187,44,162)">nil</span></p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    }</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</p></div></blockquote><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)">


















</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></p>If that&#39;s correct then I prefer the keyword in the other thread `<font face="monospace, monospace">nobreak</font>` although it could be a better.</div><div><br></div><div><a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/001110.html" rel="noreferrer" target="_blank" style="font-size:13px">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/001110.html</a></div><div><br></div><div>We&#39;d have to confirm with Lee, but their example (this thread) seems oriented around zero items rather than early exit:</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">let</span> items: <span style="color:rgb(112,61,170)">Int</span> = []</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">for</span> item <span style="color:rgb(187,44,162)">in</span> items {</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    print(item)</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)">else<span style="color:rgb(0,0,0)"> {</span></p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    print(<span style="color:rgb(209,47,27)">&quot;No items&quot;</span>)</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</p></div></blockquote><div>






<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></p>My suggestion works for zero items.<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></p></div><div><br><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></p></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 27, 2016 at 4:47 AM, Félix Cloutier <span dir="ltr">&lt;<a href="mailto:felixcca@yahoo.ca" target="_blank">felixcca@yahoo.ca</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">This is more a demonstration that the for...else construct isn&#39;t obvious than a solution to the problem. In Python, the else branch of a for loop is executed when you went through all the iterations without breaking (&quot;when the loop condition becomes false&quot;, which doesn&#39;t happen if you break from the loop).<span class="HOEnZb"><font color="#888888"><br><div>
<br><span style="color:rgb(0,0,0);font-family:&#39;Lucida Grande&#39;;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none">Félix</span>
</div></font></span><div><div class="h5">

<br><div><blockquote type="cite"><div>Le 25 janv. 2016 à 23:14:23, Andrew Bennett via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; a écrit :</div><br><div><div dir="ltr">This may do what you want:<div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:rgb(187,44,162)">let</span> values: [<span style="color:rgb(112,61,170)">Int</span>] = [<span style="color:rgb(39,42,216)">1</span>,<span style="color:rgb(39,42,216)">2</span>,<span style="color:rgb(39,42,216)">3</span>,<span style="color:rgb(39,42,216)">4</span>]</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:rgb(187,44,162)">if</span> <span style="color:rgb(187,44,162)">let</span> sequence = <span style="color:rgb(49,89,93)">nonEmptySequence</span>(<span style="color:rgb(79,129,135)">values</span>) {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">        <span style="color:rgb(187,44,162)">for</span> element <span style="color:rgb(187,44,162)">in</span> sequence {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">            <span style="color:rgb(61,29,129)">print</span>(<span style="color:rgb(209,47,27)">&quot;element: </span>\<span style="color:rgb(209,47,27)">(</span>element<span style="color:rgb(209,47,27)">)&quot;</span>)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">        }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:rgb(187,44,162)">else</span> {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">        <span style="color:rgb(61,29,129)">print</span>(<span style="color:rgb(209,47,27)">&quot;empty!&quot;</span>)</div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">







</p><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    }</div></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></div>It&#39;s also more flexible, you can do work after the for loop (that work won&#39;t execute in the else), you can also use PeekSequence directly to get the first value. This is handy for something like an average (reduce) where you don&#39;t necessarily have a zero value.</div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></div>The implementation can be found here: <a href="https://github.com/therealbnut/PeekSequence" target="_blank">https://github.com/therealbnut/PeekSequence</a></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 26, 2016 at 12:59 AM, Matthew Johnson 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"><div dir="auto"><div><br><br>Sent from my iPad</div><span><div><br>On Jan 25, 2016, at 3:41 AM, Howard Lovatt via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div></div><div>It would be easy enough to add:</div><div><br></div><ul style="margin:0px;padding:0px;width:auto;list-style:none"><li style="text-indent:0px;border-left-style:none;margin-left:4em;padding-bottom:0px!important"><font face="UICTFontTextStyleTallBody"><span style="background-color:rgba(255,255,255,0)"><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;min-height:auto!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">func</code> <code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;min-height:auto!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">forEach</code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;min-height:auto!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">(</code></span></font></li><li style="text-indent:0px;border-left-style:none;margin-left:4em;padding-bottom:0px!important"><font face="UICTFontTextStyleTallBody"><span style="background-color:rgba(255,255,255,0)"><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;min-height:auto!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">    @</code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;min-height:auto!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">noescape</code> elements <code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;min-height:auto!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">body</code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;min-height:auto!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">: (</code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;min-height:auto!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">Element</code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;min-height:auto!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">) </code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;min-height:auto!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">throws<font face="UICTFontTextStyleTallBody"> -&gt; Void</font></code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;min-height:auto!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">,</code></span></font></li><li style="text-indent:0px;border-left-style:none;margin-left:4em;padding-bottom:0px!important"><font face="UICTFontTextStyleTallBody"><span style="background-color:rgba(255,255,255,0)"><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;min-height:auto!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">    @noescape otherwise otherwise: () throws -&gt; Void</code></span></font></li><li style="text-indent:0px;border-left-style:none;margin-left:4em;padding-bottom:0px!important"><font face="UICTFontTextStyleTallBody"><span style="background-color:rgba(255,255,255,0)"><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;min-height:auto!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">) </code><code style="padding:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;background-image:none!important;border:0px!important;float:none!important;min-height:auto!important;line-height:1.1em!important;margin:0px!important;outline:0px!important;overflow:visible!important;vertical-align:baseline!important;width:auto!important;min-height:inherit!important">rethrows</code></span></font></li></ul><div><font face="monospace"><br></font></div><div><font face="monospace">to the standard library or write it yourself.</font></div></div></blockquote><div><br></div></span><div>Not unless / until we get the ability for a noescape closure to influence control flow (break, return, etc).  Even then this is clunkier than adding else to the language would be.</div><div><div><br><blockquote type="cite"><div><div><br>On 23 Jan 2016, at 12:59 PM, Félix Cloutier via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div>I frequently need something like that and I&#39;d like to have it in Swift too.<br><div>
<br><span style="font-family:&#39;Lucida Grande&#39;;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">Félix</span>
</div>

<br><div><blockquote type="cite"><div>Le 22 janv. 2016 à 13:22:45, Ben Langmuir via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; a écrit :</div><br><div><div>Previous discussion here:<br><a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/001110.html" target="_blank">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/001110.html</a><br><br><br><blockquote type="cite">On Jan 22, 2016, at 8:22 AM, Lee M via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br><br>This has likely been discussed already, but I haven&#39;t been able to find it anywhere.<br>Example:<br><br>    let items: Int = []<br><br>    for item in items {<br>        print(item)<br>    }<br>    else {<br>        print(&quot;No items&quot;)<br>    }<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" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></blockquote><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" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></div></blockquote></div><br></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></div></div></div><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>
<br></blockquote></div><br></div>
_______________________________________________<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" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></div></div></blockquote></div><br></div>