<div dir="ltr">Oooh - didn't know about that - very nice.<div><br></div><div>Thanks,</div><div>Kurt</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 14, 2016 at 10:31 AM, Joe Groff <span dir="ltr"><<a href="mailto:jgroff@apple.com" target="_blank">jgroff@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><blockquote type="cite"><span class=""><div>On Mar 12, 2016, at 3:20 PM, Kurt Werle via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br></span><span class=""><div><div dir="ltr"><div><div><div>let x = 1</div><div>let y = 2</div><div>let z = 3</div><div><br></div><div>let condition1 = x > y</div><div>let condition2 = z > x</div><div><br></div><div>switch (condition1, condition2) { // Treat your conditions as peers</div><div>case (true, _): // true & whatever</div><div> break</div><div>case (false, true): // false, true</div><div> break</div><div>case (false, false): // false, false</div><div> break</div><div>// no default needed - we covered all the cases</div><div>}</div></div></div><div><br></div></div></div></span></blockquote><div><br></div><div>You can also use tuple labels here to aid readability:</div><div><br></div><div>switch (x_y: x > y, z_x: z > x) {</div><div>case (x_y: true, z_x: _):</div><div> ...</div><div>}</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-Joe</div></font></span><div><div class="h5"><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 12, 2016 at 1:17 PM, Ted F.A. van Gaalen via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><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>
<br>
• if condition 1 {<br>
• statements to execute if condition 1 is true<br>
• } else if condition 2 {<br>
• statements to execute if condition 2 is true<br>
• } else {<br>
• statements to execute if both conditions are false<br>
• }<br>
<br>
what I currently do to prevent this:<br>
<br>
switch true<br>
{<br>
case film == 2010:<br>
itsFullOfStars(monolith)<br>
<br>
case terriblyWrongPresident():<br>
initiateNewElections()<br>
<br>
case b > c:<br>
c = b<br>
<br>
case d > c:<br>
c = d<br>
<br>
default:<br>
break // or something else to do, if all other conditions are fase<br>
}<br>
<br>
<br>
This works perfectly well, looks good too, I think, but is it right thing to do it this way,<br>
as in principle 'switch’ is perhaps more intended to evaluate variables?<br>
<br>
Python has its “elif” keyword…<br>
<br>
So what about, an ‘ifs’ statement group in Swift:<br>
<br>
<br>
ifcases // or another keyword, perhaps<br>
{<br>
case a > b:<br>
b = a<br>
case c < d:<br>
b = c<br>
}<br>
without fall-through option.<br>
perhaps also without default<br>
<br>
<br>
What do you think?<br>
<br>
TedvG<br>
<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div><a href="mailto:kurt@circlew.org" target="_blank">kurt@CircleW.org</a><br><a href="http://www.circlew.org/kurt/" target="_blank">http://www.CircleW.org/kurt/</a><br></div>
</div></div>
_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div></div></div><br></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">kurt@CircleW.org<br><a href="http://www.CircleW.org/kurt/" target="_blank">http://www.CircleW.org/kurt/</a><br></div>
</div>