<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 12, 2016, at 3:20 PM, Kurt Werle 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=""><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></blockquote><div><br class=""></div><div>You can also use tuple labels here to aid readability:</div><div><br class=""></div><div>switch (x_y: x > y, z_x: z > x) {</div><div>case (x_y: true, z_x: _):</div><div> ...</div><div>}</div><div><br class=""></div><div>-Joe</div><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" 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="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>
_______________________________________________<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>