<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I'm not really seeing the advantage of `<font face="Menlo" class="">for item in collection else</font>` being discussed or a compelling use case that motivates a language change.</div><div class=""><br class=""></div><div class="">You can check the empty case first for empty collections:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">if collection.isEmpty {</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; ...</font></div><div class=""><font face="Menlo" class="">} else for item in collection {</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; ...</font></div><div class=""><font face="Menlo" class="">}</font></div><div class=""><br class=""></div><div class="">If you're filtering while iterating, you can use an access counter, for what is surely an uncommon test, or better yet, filter first and use the leading isEmpty test:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">var access = 0</font></div><div class=""><font face="Menlo" class="">for item in collection where condition {</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; access += 1</font></div><div class=""><font face="Menlo" class="">}</font></div><div class=""><font face="Menlo" class="">if access == 0 {</font></div><div class=""><font face="Menlo" class="">}</font></div><div class=""><br class=""></div><div class="">It seems to me that the only reason the language should change would be to handle abnormal loop processing, such as a break, but then why not throw an error and embed the for-loop in a do-catch? And honestly, I don't really think I'd ever use this or could think of a scenario where I'd need this.</div><div class=""><br class=""></div><div class="">-- E</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 3, 2017, at 10:01 AM, Thorsten Seitz via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class=""><div class=""></div><div class="">I would prefer `ifNone:` instead of `otherwise` as it makes the semantics clearer IMHO.</div><div class=""><br class=""></div><div class="">-Thorsten&nbsp;</div><div class=""><br class="">Am 03.02.2017 um 12:50 schrieb Haravikk via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt;:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 2 Feb 2017, at 13:44, Derrick Ho &lt;<a href="mailto:wh1pch81n@gmail.com" class="">wh1pch81n@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class="">Maybe we can add a new parameter "otherwise" to the forEach method<br class=""><br class="">[1,2,3,4].forEach({<br class="">  // do something<br class="">}<br class="">, otherwise: {<br class="">  // do something if it is an empty array<br class="">})<br class=""></div></blockquote><div class=""><br class=""></div><div class="">That could be a decent compromise; just tried a simple extension and the following seems to work quite nicely:</div><div class=""><br class=""></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Sequence</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> {</span></div></div></div><div class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> forEach(</span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">_</span><span style="font-variant-ligatures: no-common-ligatures" class=""> body: (Iterator.Element) </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span><span style="font-variant-ligatures: no-common-ligatures" class=""> -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Void</span><span style="font-variant-ligatures: no-common-ligatures" class="">, otherwise: () </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span><span style="font-variant-ligatures: no-common-ligatures" class=""> -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Void</span><span style="font-variant-ligatures: no-common-ligatures" class="">) </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">rethrows</span><span style="font-variant-ligatures: no-common-ligatures" class=""> -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Void</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div></div></div><div class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">                </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">var</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> it = </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">self</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.makeIterator()</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">                </span></span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> first = it.next() {</span></div></div></div><div class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">                        </span></span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">try</span><span style="font-variant-ligatures: no-common-ligatures" class=""> body(first)</span></div></div></div><div class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">                        </span></span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">while</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> current = it.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">next</span><span style="font-variant-ligatures: no-common-ligatures" class="">() { </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">try</span><span style="font-variant-ligatures: no-common-ligatures" class=""> body(current) }</span></div></div></div><div class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>} </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">else</span><span style="font-variant-ligatures: no-common-ligatures" class=""> { </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">try</span><span style="font-variant-ligatures: no-common-ligatures" class=""> otherwise() }</span></div></div></div><div class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</span></div></div></div><div class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div></div><div class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div></div></div><div class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> names = [</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"foo"</span><span style="font-variant-ligatures: no-common-ligatures" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"bar"</span><span style="font-variant-ligatures: no-common-ligatures" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"baz"</span><span style="font-variant-ligatures: no-common-ligatures" class="">], empty:[</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span><span style="font-variant-ligatures: no-common-ligatures" class="">] = []</span></div></div></div><div class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">names.forEach({ print($0) }, otherwise: { print(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"no names"</span><span style="font-variant-ligatures: no-common-ligatures" class="">) })</span></div></div></div><div class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">empty.forEach({ print($0) }, otherwise: { print(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"no names"</span><span style="font-variant-ligatures: no-common-ligatures" class="">) })</span></div></div></div></blockquote><div class=""><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span></div></div></div><div class=""><br class=""></div><div class="">Of course it lacks the ability to use continue or break, so the question is; does it add enough utility to add, or is it better left to developers to extend themselves?</div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote"><div dir="ltr" class="">On Thu, Feb 2, 2017 at 6:31 AM Haravikk via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg">I'm of two minds on this feature; I kind of support the idea of the construct, especially because there are some behind the scenes optimisations it can do, and it can look neater.</div><div class="gmail_msg">However, I'm not at all keen on the re-use of else; if there were a better keyword I might suppose that, for example "empty" or something like that, but nothing I can think of feels quite right.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I mean, when it comes down to it the "best" way to write the loop is like:</div><div class="gmail_msg"><br class="gmail_msg"></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="gmail_msg"><div style="font-family:Helvetica;font-size:12px" class="gmail_msg"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(61,29,129)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="gmail_msg">var</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">&nbsp;it =&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="gmail_msg">names</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">.</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">makeIterator</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">()</span></div></div><div style="font-family:Helvetica;font-size:12px" class="gmail_msg"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="gmail_msg">if</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="gmail_msg">let</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">&nbsp;first =&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="gmail_msg">it</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)" class="gmail_msg">next</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">() {</span></div></div><div style="font-family:Helvetica;font-size:12px" class="gmail_msg"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"><span class="m_3702368787638856720Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)" class="gmail_msg">print</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">(first)</span></div></div><div style="font-family:Helvetica;font-size:12px" class="gmail_msg"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"><span class="m_3702368787638856720Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="gmail_msg">while</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="gmail_msg">let</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">&nbsp;current =&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="gmail_msg">it</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)" class="gmail_msg">next</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">() {&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)" class="gmail_msg">print</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">(current) }</span></div></div></div></blockquote></div><div style="word-wrap:break-word" class="gmail_msg"><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="gmail_msg"><div style="font-family:Helvetica;font-size:12px" class="gmail_msg"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(209,47,27)" class="gmail_msg"><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">}&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="gmail_msg">else</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">&nbsp;{&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)" class="gmail_msg">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">(</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">"no names"</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">) }</span></div></div></div></blockquote></div><div style="word-wrap:break-word" class="gmail_msg"><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="gmail_msg"></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">However this is a horrible thing to do in your own code, especially if the loop body is larger than one line, but is just fine if it's done behind the scenes for you (complete with unwrapping of the iterators if their type is known).</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Which is why I kind of like the idea of having the construct itself; otherwise, like others, I use the less "correct" option like so (for sequences):</div><div class="gmail_msg"><br class="gmail_msg"></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><div class="gmail_msg"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(61,29,129)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="gmail_msg">var</span><span style="color:rgb(209,47,27);font-variant-ligatures:no-common-ligatures" class="gmail_msg">&nbsp;empty =&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="gmail_msg">true</span></div></div><div class="gmail_msg"><div class="gmail_msg"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="gmail_msg">for</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">&nbsp;name&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="gmail_msg">in</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="gmail_msg">names</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">&nbsp;{&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)" class="gmail_msg">print</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">(name);&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="gmail_msg">empty</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">&nbsp;=&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="gmail_msg">false</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">&nbsp;}</span></div></div><div class="gmail_msg"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(209,47,27)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="gmail_msg">if</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="gmail_msg">empty</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">&nbsp;{&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)" class="gmail_msg">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">(</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">"no names"</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">) }</span></div></div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">At which point I simply hope that the compiler optimises away the assignment (since it only actually does something on the first pass).</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">So yeah, I can see a use for it, but I'd prefer a construct other than for/else to do it; at the very least a different keyword, as there's the possibility we could also have a while/else as well and it would need to be very clear, which I don't feel that for/else is.</div></div><div style="word-wrap:break-word" class="gmail_msg"><br class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On 2 Feb 2017, at 11:06, Jeremy Pereira via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_3702368787638856720Apple-interchange-newline gmail_msg"><div class="gmail_msg"><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg"><br class="m_3702368787638856720Apple-interchange-newline gmail_msg">On 1 Feb 2017, at 18:29, Chris Davis via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br class="gmail_msg"><br class="gmail_msg">ah! I forgot about the break semantics, that’s definitely one for the con list.<br class="gmail_msg"><br class="gmail_msg">I like Nicolas’ solution, clear to read.<br class="gmail_msg"><br class="gmail_msg"><blockquote type="cite" class="gmail_msg">On 1 Feb 2017, at 18:18, Nicolas Fezans &lt;<a href="mailto:nicolas.fezans@gmail.com" class="gmail_msg" target="_blank">nicolas.fezans@gmail.com</a>&gt; wrote:<br class="gmail_msg"><br class="gmail_msg">I tend to write this kind of treatment the other way around...<br class="gmail_msg"><br class="gmail_msg">if names.isEmpty {<br class="gmail_msg"><span class="m_3702368787638856720Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>// do whatever<br class="gmail_msg">} // on other cases I might have a few else-if to treat other cases that need special treament<br class="gmail_msg">else {<br class="gmail_msg"><span class="m_3702368787638856720Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>for name in names {<br class="gmail_msg"><span class="m_3702368787638856720Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span><span class="m_3702368787638856720Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>// do your thing<br class="gmail_msg"><span class="m_3702368787638856720Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>}<br class="gmail_msg">}<br class="gmail_msg"><br class="gmail_msg"></blockquote></blockquote><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg"><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps: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" class="gmail_msg">This only works if you know the size of the sequence before you start iterating it. You can, for example, iterate a lazy sequence and calculating its size before iterating it defeats the object.Thus for { … } else { … } where the else block only executes if the for block was never executed does have some utility.</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg"><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps: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" class="gmail_msg">However, I am not in favour adding it. The same functionality can be achieved by counting the number of iterations and testing the count afterwards (or by using a boolean). It takes a couple of extra lines of code and an extra variable, but I think that is a Good Thing. It’s more explicit and (as the Python example shows) there could be hidden subtleties that confuse people if for … else … is badly designed. Also, in many cases, I would argue that treating the zero element sequence differently to the n &gt; 0 element sequence is a code smell. About the only use-case I can think of off the top of my head is UI presentation e.g. “your search didn’t return any results” instead of a blank page.</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg"><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps: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" class="gmail_msg">Talking of Python, Swift is not Python and the argument not to implement a feature because its semantics conflict with the semantics of a similar looking feature in another language is bogus. I don’t see the Python for … else being different (and having looked it up to see what you all were talking about, my opinion is that the Python for … else is a disaster) as being a legitimate con to this cleaner and more logical idea in Swift.</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg"><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg"><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg"><blockquote type="cite" class="gmail_msg"><br class="gmail_msg"></blockquote></blockquote><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps: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" class="gmail_msg">_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps: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" class="gmail_msg">swift-evolution mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg"><a href="mailto:swift-evolution@swift.org" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class="gmail_msg"></div>_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>
</div></blockquote></div><br class=""></div></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>