back

by lerno·1y ago·view on hn ↗
You have both in C3:

    switch (x) {
       case 0:
         ...
       case 1 + 1:
         ...
    }
This will behave in the normal way. But you can also have:

    switch {
        case foo() > 0:
          ...
        case bar() + baz() == s:
          ...
    }
In which case it lowers to the corresponding if-else.
1 comments
I am not a fan of this design in a low level language. The first version of switch does exactly one thing and is very clear. The second now is forcing me to think both about branching logic and control flow. I understand the surface level appeal of the syntax, but if I encountered code written with this feature in the wild, I would think something must have gone wrong in the program design.
It's very simple, the latter describes an `if-else` chain. No more complicated than that. Can you explain what your concern is?
i think hlls sometimes distinguish between these situations with a different keyword.