3 ms·
'goto case' is a thing? I'm so going to have fun with that
by stuartd 10y ago
'goto case' is a thing? I'm so going to have fun with that
- int_19h 10y agoIt has always been a thing. The original C# design was to take the C switch statement as is, but tighten it up to avoid crazy stuff like Duff's device, and to make non-obvious implicit things explicit. Consequently, C# requires that control flow provably cannot reach the end of any non-empty case block (to avoid implicit fallthrough that normally happens in C, Java etc). Normally this means that you must use `break` (or something else that transfers control, like `continue`, `throw` or `return`). But fallthrough is actually useful sometimes, and `goto case` provides you with a way to request it explicitly - and then ramps it power up a notch, because why not? Amusingly, this is something that C doesn't have, even though its case labels are true labels (allowing for Duff's device and similar tricks). If you want to goto them, you need to add an explicit named label there.