Article View: comp.lang.c
Article #240Re: Taming The Switch-Statement
From: Keith Thompson
Date: Sun, 11 Oct 2026 21:28
Date: Sun, 11 Oct 2026 21:28
37 lines
3276 bytes
3276 bytes
bart <bc@freeuk.com> writes:
[...]
> 'break' to quit a loop early is part of the language, so why shouldn't
> someone make use it?
Agreed. (There are coding styles that require loops to exit only at the
bottom, but that's not what we're talking about.)
> It just its use can be interfered with when 'switch' is involved.
Yes. Everyone here knows that, and knew it before you started talking
about it.
Michael S wrote above that "The cases where I want to break out of
the loop from the switch in the body of the loop are very common."
Tim Rentsch questioned the "very common" part of that, and asked
for an example. You jumped in and asserted that an example isn't
necessary, because you misunderstood what was being said. *Of
course* there are cases where someone might want to break out of
a loop from a nested switch.
> That that happens and needs a workaround, is not satisfactory. The
> issue exists 100% because of sharing the 'break' keyword for two
> different purposes.
Yes, the overloading of the "break" keyword can be inconvenient.
It makes it difficult to break out of a loop from within a switch
statement. Again, everyone here knows that.
Breaking out of an outer loop from within an inner loop is just
as much of a problem. "break NAME;" proposed for C2y, would solve
both problems. (I just found out that recent versions of gcc and
clang support this as an extension or with "-std=c2y".)
--
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:
<11agv1t$30q22$2@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> <11ae56o$cjlv$4@dont-email.me> <20261010230355.00005189@yahoo.com> <864iesjx6e.fsf@linuxsc.com> <11afvqt$2kloc$1@dont-email.me> <11ag37o$2ln0a$1@dont-email.me> <11agbsh$2pbk7$1@dont-email.me> <11aggaq$2qqh9$1@dont-email.me> <11agils$2s3tg$1@dont-email.me>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: Sun, 11 Oct 2026 14:28:29 -0700 Organization: None to speak of Lines: 37 Message-ID: <11agv1t$30q22$2@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> <11ae56o$cjlv$4@dont-email.me> <20261010230355.00005189@yahoo.com> <864iesjx6e.fsf@linuxsc.com> <11afvqt$2kloc$1@dont-email.me> <11ag37o$2ln0a$1@dont-email.me> <11agbsh$2pbk7$1@dont-email.me> <11aggaq$2qqh9$1@dont-email.me> <11agils$2s3tg$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Sun, 11 Oct 2026 21:28:30 +0000 (UTC) Injection-Info: kst.eternal-september.org; logging-data="3172418"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Y2+ylhJvHAPCWqaLla6+T"; posting-host="50698cca2518b68a86663845e71c144a" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:YDhZx9/ypX4pZaPOM9jmu4g2o94= sha256:nrIiyREi4KsWJu0nYdzPmmvWKuYMOQmbrZNXy76IDtA= sha1:ABLNP4m1z/9WdkXbqjzBCKPMcYQ= sha256:MaZJptuOl694eu7sOCy8vN/SXbtc2nWZsIzweQ5wL+I=