<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 agree. A for-else loop with different semantics than python would be error-prone for many people.</div>
<br class="">
<br class="">
<div>
<blockquote type="cite" class="">
<div class="">On 1 Feb 2017, at 18:17, Jacob Bandes-Storch via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">One possible con: this is subtly but extremely different from Python, where a for loop's else clause is executed only if there was no `break` from the loop.<br class="">
<div class="gmail_quote">
<div dir="ltr" class="">On Wed, Feb 1, 2017 at 8:48 AM Chris Davis via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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">Hi,
<div class="gmail_msg"><br class="gmail_msg">
</div>
<div class="gmail_msg">Often when I’m programming I stumble upon this scenario:</div>
<div class="gmail_msg"><br class="gmail_msg">
</div>
<div class="gmail_msg">I have a list of items that may or may not be empty - if it’s full, I do one thing, if it’s empty I do something else, my code looks like this:</div>
<div class="gmail_msg"><br class="gmail_msg">
</div>
<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:#ba2da2" class="gmail_msg">class</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> Example_1</span></div>
<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></div>
<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"> </span>
<span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">let</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg"> names = [</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">"Chris"</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">,
</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">"John"</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">,
</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">"Jordan"</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">]</span></div>
<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="gmail_msg"> </span><br class="gmail_msg m_-8459319842671557986webkit-block-placeholder">
</div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class="gmail_msg">
<span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg"> </span>
<span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">/// Loop over names, if no names, print no names</span></div>
<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>
<span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">func</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> run()</span></div>
<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></div>
<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><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">for</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> name
</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">in</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">
</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="gmail_msg">names</span></div>
<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></div>
<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><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81" class="gmail_msg">print</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">(name)</span></div>
<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></div>
<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="gmail_msg"> </span><br class="gmail_msg m_-8459319842671557986webkit-block-placeholder">
</div>
<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><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">if</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">
</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" 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;color:#703daa" class="gmail_msg">count</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">
== </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8" class="gmail_msg">0</span></div>
<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></div>
<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><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81" 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;color:#d12f1b" class="gmail_msg">"no
names"</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">)</span></div>
<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></div>
<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></div>
<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></div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class="gmail_msg">
<br class="gmail_msg">
<span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"></span></div>
<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:#ba2da2" class="gmail_msg">let</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> exampleOne =
</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="gmail_msg">Example_1</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">()</span></div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">exampleOne</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">.</span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d" class="gmail_msg">run</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">()</span></div>
</div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg"><br class="gmail_msg">
</span></div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">However, Personally, I would find it more pleasing to write something like this:</span></div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg"><br class="gmail_msg">
</span></div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">
<div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">class</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> Example_2_Proposed</span></div>
<div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">{</span></div>
<div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">
</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">let</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> names:[</span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="gmail_msg">String</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">]
= []</span></div>
<div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> </span><br class="gmail_msg m_-8459319842671557986webkit-block-placeholder">
</div>
<div style="margin:0px;line-height:normal;color:rgb(0,132,0)" class="gmail_msg"><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">
</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">/// Loop over names, if no names, print no names</span></div>
<div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">
</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">func</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> run()</span></div>
<div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> {</span></div>
<div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">
</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">for</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> name
</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">in</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">
</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187" class="gmail_msg">names</span></div>
<div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> {</span></div>
<div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">
</span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81" class="gmail_msg">print</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">(name)</span></div>
<div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> }
</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">else</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> {</span></div>
<div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">
</span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81" 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;color:#d12f1b" class="gmail_msg">"no
names"</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">)</span></div>
<div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> }</span></div>
<div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> }</span></div>
<div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">}</span></div>
<div style="margin:0px;line-height:normal;min-height:13px" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"></span><br class="gmail_msg">
</div>
<div style="margin:0px;line-height:normal;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">let</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg"> exampleTwo =
</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">Example_2_Proposed</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">()</span></div>
<div style="margin:0px;line-height:normal;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">exampleTwo</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">.</span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d" class="gmail_msg">run</span><span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">()</span></div>
<div style="margin:0px;line-height:normal;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg"><br class="gmail_msg">
</span></div>
<div style="margin:0px;line-height:normal;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">The difference here is a “for-else” type syntax where if there were no items in the array it would simply fall through to the else statement.</span></div>
<div style="margin:0px;line-height:normal;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg"><br class="gmail_msg">
</span></div>
<div style="margin:0px;line-height:normal;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">What would be the pros/cons of introducing such syntax?</span></div>
<div style="margin:0px;line-height:normal;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg"><br class="gmail_msg">
</span></div>
<div style="margin:0px;line-height:normal;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">Is there’s a way of doing something similar in swift already?</span></div>
<div style="margin:0px;line-height:normal;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg"><br class="gmail_msg">
</span></div>
<div style="margin:0px;line-height:normal;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">Thanks</span></div>
<div style="margin:0px;line-height:normal;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg"><br class="gmail_msg">
</span></div>
<div style="margin:0px;line-height:normal;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg">Chris</span></div>
<div style="margin:0px;line-height:normal;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg"><br class="gmail_msg">
</span></div>
<div style="margin:0px;line-height:normal;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg"><br class="gmail_msg">
</span></div>
<div style="margin:0px;line-height:normal;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg"><br class="gmail_msg">
</span></div>
<div style="margin:0px;line-height:normal;color:rgb(79,129,135)" class="gmail_msg">
<span style="font-variant-ligatures: no-common-ligatures;" class="gmail_msg"><br class="gmail_msg">
</span></div>
</span></div>
</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>
_______________________________________________<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>