[swift-evolution] Alternative For Nested If Repetiion

Kenny Leung kenny_leung at pobox.com
Mon Mar 14 14:08:18 CDT 2016


I don’t see how this is significantly different from

if a > b {
    c = 1234
} else if c == d {
    a = b
} else {
    doSomething()
}

If you put them side by side, it’s pretty much equivalent in size and shape, except for a few braces.

-Kenny


> On Mar 14, 2016, at 11:41 AM, Ted F.A. van Gaalen via swift-evolution <swift-evolution at swift.org> wrote:
> 
> .. or maybe just leave out  the switch operand like so:
> 
>     switch
>    {
>          case if  a > b:
>                   c = 1234
> 
>          case c == d: 
>                  a = b
> 
>          default:
>                 doSomething()
>    }
> 
> ?
> 
> TedvG
> 
> 
> 
>> On 14.03.2016, at 19:27, Joe Groff <jgroff at apple.com> wrote:
>> 
>> 
>>> 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
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list