Lee said:
That's because you're thinking in terms of "if then else".
Absolutely. That's the way similar constructs are described in other
languages like Pascal, Scheme, Ada, and even in Fortran which predates
C.
<URL:
http://www.xploiter.com/mirrors/pascal/pas026.htm>
<URL:
http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.2.1>
<URL:
http://www.adaic.org/standards/95lrm/html/RM-5-4.html>
The switch determines the entry point into a block of statements.
When you think about it that way, fallthrough is the expected
behavior.
You could say that C doesn't have a multiway conditional like the
languages above, and instead has a computed goto statement called
"switch". You would probably technically be right too
It's just that the multiway conditional is such a useful construct, as
its general adaption in pretty much any other language family
suggests, that you *will* try to simulate it with the nearest
equivalent in the language, especially when switch is so close. And
that was also the intention of the switch statment.
Quoting from "The Ansi C Languge, 2ed" (page 59):
"Falling trough from one case to another is not robust, being prone to
disintegration when the program is modified. With the exception of
multiple labels for a single computation, fall-throughs should be used
sparingly, and commented."
Again, C's switch is from a time when expressive power was more
important than readability or even maintainability. You could do some
things with fallthorough that you can't easily do without (without
duplicating code). But I would still much rather have had a continue
statement to mark the fallthrough than the absence of a break.
We just have to live with it. We don't have to like it
/L