|
|
|
|
|
by int_19h
2316 days ago
|
|
> If you have set-based lists, you don't need "fall through" behavior because you can have more than one item per matching expression. This is not entirely true. Ranges and sets allow you to run the same code for different inputs. Fallthrough allows you to run partially the same code for different inputs. It's a rare case, so I don't think its utility warrants making fallthrough behavior the default. But it's nice to have it explicitly, like "goto case" in C#. Anyway, the reason why it is the way it is in C, is because case labels are literally labels, and the switch statement itself is just a branched goto - which is why e.g. Duff's Device is a thing. And that, in turn, is probably because it's a descendant of "switch" in Algol-60, which was basically an array of labels. |
|
True, but it's a screwy way to manage such overlaps. The volume of errors and confusion exceeds the benefits in my opinion. There are other ways to do such. For non-trivial conditionals (such as overlaps), if-else is often the better tool anyhow. Case/Switch should only be used for simple mutually-exclusive value look-ups.