News for hackers. Stuff that matters.
Re:Clear is better than clever [pdf] by Schattenbaer on Monday May 06, 2019 @11:45AM (#19840445)
I have also seen switch statements used (abused?) to do a similar thing. Since a switch executes the first statement that is equivalent to the control expression you can pass true as the control expression, e.g.:

  switch(true) {
    cond1: return 1;
    cond2 && cond3: return 10;
    //etc
  }
Not sure I'd recommend it but it works in a few languages :)

Elixir has cond that does this nicely without resorting to strange switch statements:

https://elixir-lang.org/getting-started/case-cond-and-if.htm...

There are no comments on this comment yet.