[swift-evolution] Alternative For Nested If Repetiion

Ted F.A. van Gaalen tedvgiosdev at gmail.com
Mon Mar 14 13:41:22 CDT 2016


.. 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



More information about the swift-evolution mailing list