Why don't languages use explicit fall-through on switch statements?
- by zzzzBov
I was reading Why do we have to use break in switch?, and it led me to wonder why implicit fall-through is allowed in some languages (such as PHP and JavaScript), while there is no support (AFAIK) for explicit fall-through.
It's not like a new keyword would need to be created, as continue would be perfectly appropriate, and would solve any issues of ambiguity for whether the author meant for a case to fall through.
The currently supported form is:
switch (s) {
case 1:
...
break;
case 2:
... //ambiguous, was break forgotten?
case 3:
...
break;
default:
...
break;
}
Whereas it would make sense for it to be written as:
switch (s) {
case 1:
...
break;
case 2:
...
continue; //unambiguous, the author was explicit
case 3:
...
break;
default:
...
break;
}
For purposes of this question lets ignore the issue of whether or not fall-throughs are a good coding style.
Are there any languages that exist that allow fall-through and have made it explicit?
Are there any historical reasons that switch allows for implicit fall-through instead of explicit?