[swift-evolution] Alternative For Nested If Repetiion

Joe Groff jgroff at apple.com
Mon Mar 14 13:27:38 CDT 2016


> On Mar 14, 2016, at 11:25 AM, Ted F.A. van Gaalen <tedvgiosdev at gmail.com> wrote:
> 
> Unexpected ways :o) 
> All very nice and well but readable?
> I was looking a new language element
> that would be similar to
>    Switch true ….
> but then limited for cases
> which are logical expressions only.  
> Ok, Perhaps it is not that important.
> I will forget it and will continue
> to use “switch true”  case <logical expression>:  etc.
> sorry I brought it forward.
> TedvG

If the "true" bothers you, you can also switch over "nothing" and use where clauses:

switch () {
case () where cond1: ...
case () where cond2: ...
}

It might be interesting to consider a shorthand:

switch {
where cond1: ...
where cond2: ...
}

-Joe


More information about the swift-evolution mailing list