3 ms·
In D, if there are no intervening statements: case 1: case 2: ... code ... the fallthrough is allowed. case 1: ... code ... ca
by WalterBright 3y ago
In D, if there are no intervening statements:
case 1:
case 2:
... code ...
the fallthrough is allowed.
case 1:
... code ...
case 2:
... code ...
Is an error. But `goto case` can be used:
case 1:
... code ...
goto case;
case 2:
... code ...
which makes it clear. No new keywords are needed. C could adopt this easily. All those /* fallthrough */ comments and warnings and compiler switches will just go away.
Oh, and obviously:
case 1:
... code ...
goto default;
default:
... code ...
also works!