Article View: comp.lang.c
Article #158Re: Taming The Switch-Statement
From: Keith Thompson
Date: Sat, 10 Oct 2026 23:56
Date: Sat, 10 Oct 2026 23:56
33 lines
2772 bytes
2772 bytes
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
[...]
> C's switch statement is essentially a computed goto. It goes back
> to BCPL (1967), which had different syntax (SWITCHON, CASE, ENDCASE)
> but similar semantics. BCPL's predecessor, CPL, had a more explicit
> computed goto that could be used in the same way; the target of a
> "go to" could be a label expression.
[...]
I realize I skipped over an entire language.
C's immediate ancestor B had the same switch/case/break syntax as C.
Ken Thompson's B manual, from 1972, doesn't mention "break" (for
either switch statements or loops), and apparently required "goto"
to break out of a loop or switch statement. There's a sample program
with a switch statement that uses "goto" on each case, but it jumps
to the top of a loop, not to the bottom of the switch.
Kernighan's B tutorial does use "break". Apparently "break" was
added to the language some time after the manual was written.
B's parent BCPL had both "BREAK" and "ENDCASE". Apparently both
were dropped when B was designed, and then only one was reintroduced.
https://www.nokia.com/bell-labs/about/dennis-m-ritchie/kbman.html
https://www.nokia.com/bell-labs/about/dennis-m-ritchie/kbman.pdf
https://www.nokia.com/bell-labs/about/dennis-m-ritchie/btut.html
https://www.nokia.com/bell-labs/about/dennis-m-ritchie/btut.pdf
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Technical Details
Message-ID:
<11aejbh$24k8m$6@kst.eternal-september.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!kst.eternal-september.org!.POSTED!not-for-mailReferences:
<119qf6l$2rmg3$1@dont-email.me> <11ac0mi$19kfd$1@dont-email.me> <11ac2jv$1a84t$1@dont-email.me> <11ac783$1bkuo$1@kst.eternal-september.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!kst.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson <Keith.S.Thompson+u@gmail.com> Newsgroups: comp.lang.c Subject: Re: Taming The Switch-Statement Date: Sat, 10 Oct 2026 16:56:33 -0700 Organization: None to speak of Lines: 33 Message-ID: <11aejbh$24k8m$6@kst.eternal-september.org> References: <119qf6l$2rmg3$1@dont-email.me> <11ac0mi$19kfd$1@dont-email.me> <11ac2jv$1a84t$1@dont-email.me> <11ac783$1bkuo$1@kst.eternal-september.org> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Sat, 10 Oct 2026 23:56:34 +0000 (UTC) Injection-Info: kst.eternal-september.org; logging-data="2248982"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19DStkdY6CgKTuvvz1UvBb6"; posting-host="29efadadb268dc6914862df94b2a05d4" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:iq5ug3H6mOdYmqHHoM85z6pwFgY= sha256:opBIJyA9+9XkivCIxit0KEoxjWKd7o2ZNI5sPjOzaJw= sha1:V2cXnSbn/9GglQGdD02XAt/fu/Q= sha256:mkyNxOM7DnMO46x4rZmzUpAnTAMCiRnIe/BPM3Yh5pY=