<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) <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=""> Switch true ….</div><div class="">but then limited for cases</div><div class="">which are logical expressions only. </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” case <logical expression>: 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 <<a href="mailto:kurt@circlew.org" class="">kurt@circlew.org</a>> 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=""><<a href="mailto:jgroff@apple.com" target="_blank" class="">jgroff@apple.com</a>></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 <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> 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 > y</div><div class="">let condition2 = z > x</div><div class=""><br class=""></div><div class="">switch (condition1, condition2) { // Treat your conditions as peers</div><div class="">case (true, _): // true & whatever</div><div class=""> break</div><div class="">case (false, true): // false, true</div><div class=""> break</div><div class="">case (false, false): // false, false</div><div class=""> 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 > y, z_x: z > x) {</div><div class="">case (x_y: true, z_x: _):</div><div class=""> ...</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=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></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’ is not really nice, i think:<br class="">
<br class="">
• if condition 1 {<br class="">
• statements to execute if condition 1 is true<br class="">
• } else if condition 2 {<br class="">
• statements to execute if condition 2 is true<br class="">
• } else {<br class="">
• statements to execute if both conditions are false<br class="">
• }<br class="">
<br class="">
what I currently do to prevent this:<br class="">
<br class="">
switch true<br class="">
{<br class="">
case film == 2010:<br class="">
itsFullOfStars(monolith)<br class="">
<br class="">
case terriblyWrongPresident():<br class="">
initiateNewElections()<br class="">
<br class="">
case b > c:<br class="">
c = b<br class="">
<br class="">
case d > c:<br class="">
c = d<br class="">
<br class="">
default:<br class="">
break // 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’ is perhaps more intended to evaluate variables?<br class="">
<br class="">
Python has its “elif” keyword…<br class="">
<br class="">
So what about, an ‘ifs’ statement group in Swift:<br class="">
<br class="">
<br class="">
ifcases // or another keyword, perhaps<br class="">
{<br class="">
case a > b:<br class="">
b = a<br class="">
case c < d:<br class="">
b = c<br class="">
}<br class="">
without fall-through option.<br class="">
perhaps also without 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>