<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="">Unexpected ways :o)&nbsp;<div class="">All very nice and well but readable?<div class="">I was looking a new language element</div><div class="">that would be similar to</div><div class="">&nbsp; &nbsp;Switch true ….</div><div class="">but then limited for cases</div><div class="">which are logical expressions only. &nbsp;</div><div class="">Ok, Perhaps it is not that important.</div><div class="">I will forget it and will continue</div><div class="">to use “switch true” &nbsp;case &lt;logical expression&gt;: &nbsp;etc.</div><div class="">sorry I brought it forward.</div><div class="">TedvG</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">On 14.03.2016, at 18:52, Kurt Werle &lt;<a href="mailto:kurt@circlew.org" class="">kurt@circlew.org</a>&gt; wrote:</div><div class=""><div><blockquote type="cite" class=""><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Oooh - didn't know about that - very nice.<div class=""><br class=""></div><div class="">Thanks,</div><div class="">Kurt</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Mar 14, 2016 at 10:31 AM, Joe Groff <span dir="ltr" class="">&lt;<a href="mailto:jgroff@apple.com" target="_blank" class="">jgroff@apple.com</a>&gt;</span> wrote:<br class=""><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=""><br class=""><div class=""><blockquote type="cite" class=""><span class=""><div class="">On Mar 12, 2016, at 3:20 PM, Kurt Werle via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class=""></span><span class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class="">let x = 1</div><div class="">let y = 2</div><div class="">let z = 3</div><div class=""><br class=""></div><div class="">let condition1 = x &gt; y</div><div class="">let condition2 = z &gt; x</div><div class=""><br class=""></div><div class="">switch (condition1, condition2) { // Treat your conditions as peers</div><div class="">case (true, _): // true &amp; whatever</div><div class="">&nbsp; &nbsp; break</div><div class="">case (false, true): // false, true</div><div class="">&nbsp; &nbsp; break</div><div class="">case (false, false): // false, false</div><div class="">&nbsp; &nbsp; break</div><div class="">// no default needed - we covered all the cases</div><div class="">}</div></div></div><div class=""><br class=""></div></div></div></span></blockquote><div class=""><br class=""></div><div class="">You can also use tuple labels here to aid readability:</div><div class=""><br class=""></div><div class="">switch (x_y: x &gt; y, z_x: z &gt; x) {</div><div class="">case (x_y: true, z_x: _):</div><div class="">&nbsp; ...</div><div class="">}</div><span class="HOEnZb"><font color="#888888" class=""><div class=""><br class=""></div><div class="">-Joe</div></font></span><div class=""><div class="h5"><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Sat, Mar 12, 2016 at 1:17 PM, Ted F.A. van Gaalen via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">a block of nested 'if else’&nbsp; is not really nice, i think:<br class="">
<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; • if condition 1 {<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; • statements to execute if condition 1 is true<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; • } else if condition 2 {<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; • statements to execute if condition 2 is true<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; • } else {<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; • statements to execute if both conditions are false<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; • }<br class="">
<br class="">
what I currently do to prevent this:<br class="">
<br class="">
&nbsp;switch true<br class="">
&nbsp;{<br class="">
case&nbsp; film == 2010:<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;itsFullOfStars(monolith)<br class="">
<br class="">
case terriblyWrongPresident():<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; initiateNewElections()<br class="">
<br class="">
case b &gt; c:<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; c = b<br class="">
<br class="">
case d &gt; c:<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; c = d<br class="">
<br class="">
default:<br class="">
&nbsp; &nbsp; &nbsp; &nbsp;break&nbsp; &nbsp; // or something else to do, if all other conditions are fase<br class="">
}<br class="">
<br class="">
<br class="">
This works perfectly well, looks good too, I think, but is it right thing to do it this way,<br class="">
as in principle 'switch’&nbsp; is perhaps more intended to evaluate variables?<br class="">
<br class="">
Python has its “elif”&nbsp; keyword…<br class="">
<br class="">
So what about, an ‘ifs’&nbsp; statement group in Swift:<br class="">
<br class="">
<br class="">
ifcases&nbsp; &nbsp; &nbsp; // or another keyword, perhaps<br class="">
{<br class="">
&nbsp;case a &gt; b:<br class="">
&nbsp; &nbsp; b = a<br class="">
case&nbsp; c &lt; d:<br class="">
&nbsp; &nbsp;b = c<br class="">
}<br class="">
without&nbsp; fall-through option.<br class="">
perhaps also without&nbsp; default<br class="">
<br class="">
<br class="">
What do you think?<br class="">
<br class="">
TedvG<br class="">
<br class="">
<br class="">
<br class="">
<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div class=""><a href="mailto:kurt@circlew.org" target="_blank" class="">kurt@CircleW.org</a><br class=""><a href="http://www.circlew.org/kurt/" target="_blank" class="">http://www.CircleW.org/kurt/</a><br class=""></div>
</div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div></div></div><br class=""></div></blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div class="gmail_signature"><a href="mailto:kurt@circlew.org" class="">kurt@CircleW.org</a><br class=""><a href="http://www.circlew.org/kurt/" target="_blank" class="">http://www.CircleW.org/kurt/</a><br class=""></div>
</div>
</div></blockquote></div><br class=""></div></div></body></html>