Language Proposal: The 'Any' Switch Case

Meghan (she/her) - Jul 18 '19 - - Dev Community

This feature proposal is language agnostic, as I have not seen this in any language before. If you know of an existing better way to do this, please let me know :)

The tagline for this feature is like if switch had a finally block, but only ran if the successful case found was not default.

Here's what it would look like in code:

switch (number) {
  case 1:
    ...
  case 2:
    ...
  case 3:
    ...
  any:
    ...
  default:
    ...
}
Enter fullscreen mode Exit fullscreen mode

The any block would be ran in this case if and only if case 1, 2, or 3 were also caught.

As far as whether or not the block would be run before or after the given case block is up to debate, and I could see scenarios where either would be useful. So it would be ideal to allow both, but I don't have a clear idea on how you could separate the difference between a before any clause and an after any clause.

Something I've been pondering the past few days. Feedback welcome! 😃

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .