Article View: comp.lang.c
Article #156Re: Taming The Switch-Statement
From: Keith Thompson
Date: Sat, 10 Oct 2026 23:38
Date: Sat, 10 Oct 2026 23:38
31 lines
2713 bytes
2713 bytes
Michael S <already5chosen@yahoo.com> writes:
> On Sat, 10 Oct 2026 20:08:20 +0200
> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
>> On 2026-10-10 15:11, bart wrote:
>> >
>> > Well, Algol 68 doesn't even have 'break'. For unusual control-flow
>> > it needs goto.
>>
>> Yes. - And while "C" has 'goto' as well it also supports 'break' for
>> some purposes; e.g. as a loop-exit, so it makes sense to reuse that
>> keyword for other purposes as in 'switch' where it's been useful.
>
> After practicing C programming for more than 35 years I am deeply
> convinced that reuse of the same 'break' keyword for loops and for
> switch was a mistake. But then again, DRM did not have a benefit
> of hindsight.
Actually he (DMR) did. C's parent language, BCPL, had distinct BREAK
and ENDCASE keywords.
I agree that combining them both into "break" was a mistake. At this
point, I think the best solution is named loops and "break loop_name;".
There are proposals for C2y.
A distinct "endcase" keyword would have been cleaner IMHO, but code
using the existing case/break will continue to exist approximately
forever.
--
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:
<11aei9t$24k8m$4@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> <11ad5eq$1l8hg$1@dont-email.me> <11ad9fg$cjm0$4@dont-email.me> <11addhr$1oakb$1@dont-email.me> <11aduuk$cjlv$1@dont-email.me> <20261010220212.000063fd@yahoo.com>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:38:36 -0700 Organization: None to speak of Lines: 31 Message-ID: <11aei9t$24k8m$4@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> <11ad5eq$1l8hg$1@dont-email.me> <11ad9fg$cjm0$4@dont-email.me> <11addhr$1oakb$1@dont-email.me> <11aduuk$cjlv$1@dont-email.me> <20261010220212.000063fd@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Sat, 10 Oct 2026 23:38:37 +0000 (UTC) Injection-Info: kst.eternal-september.org; logging-data="2248982"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19h9sEVEFEX/EPAkdcxS/gD"; posting-host="29efadadb268dc6914862df94b2a05d4" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:lnaQyvIuEcobMlOb2RJbAc7ZLpU= sha256:9MEMHJZEy5SQUdPIvFqT1m/Pa4jfCA+xjgVY7F9j32s= sha1:IUBulAKb1jxmilVpCJJFaDOBu3k= sha256:b6k8aVz6rr7+tmh1PSqcWi2ygKMP0h6/kPEjSieWtEo=