[swift-evolution] Alternative For Nested If Repetiion

Ted F.A. van Gaalen tedvgiosdev at gmail.com
Sat Mar 12 15:17:45 CST 2016

a block of nested 'if else’  is not really nice, i think: 
	• if condition 1 {
	• statements to execute if condition 1 is true
	• } else if condition 2 {
	• statements to execute if condition 2 is true
	• } else {
	• statements to execute if both conditions are false
	• }

what I currently do to prevent this:

 switch true
case  film == 2010: 
case terriblyWrongPresident():

case b > c:
        c = b

case d > c: 
        c = d

       break    // or something else to do, if all other conditions are fase

This works perfectly well, looks good too, I think, but is it right thing to do it this way,
as in principle 'switch’  is perhaps more intended to evaluate variables?

Python has its “elif”  keyword… 

So what about, an ‘ifs’  statement group in Swift:  

ifcases      // or another keyword, perhaps                   
 case a > b: 
    b = a
case  c < d:
   b = c
without  fall-through option. 
perhaps also without  default

What do you think?



More information about the swift-evolution mailing list