3 ms·
Three things. First of all, while you can't do this: case val: case val: case val: ... You can do this in Swift, which does the same thin
by mantrax5 12y ago
Three things.
First of all, while you can't do this:
case val:
case val:
case val:
...
You can do this in Swift, which does the same thing:
case val, val, val:
...
Second, you can fall through in Swift, but you need to ask for it:
case val:
...
fallthrough
case val:
...
So don't be sad.
And third... Seriously now, it's a "very powerful programming concept"? I bet 9 times out of 10 you use this very powerful programming concept in other languages, you did it by accident, not because you needed its pawa.
- m_mueller 12y agoThanks for the clarification on how to use it in Swift - like this it's indeed the perfect solution by enforcing it to be explicit. Having multiple cases rolled into one is also a very nice option. The snark wasn't really called for though. No, I don't 'use' it by accident, that would in most cases just become a bug. I use it when it makes code more concise rather than having nested ifs. Consider for example ACL rules where you set different privileges by default according to an access level.