Article View: comp.lang.c
Article #579Re: Taming The Switch-Statement
From: Kaz Kylheku
Date: Mon, 19 Oct 2026 23:41
Date: Mon, 19 Oct 2026 23:41
67 lines
4685 bytes
4685 bytes
On 2026-10-16, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>> I find "break NAME;", where "NAME" is the name of an enclosing
>>> construct, unambiguously better than "break N;", where N is the
>>> number of levels to break out of. [...]
>>
>> Definitely.
>>
>>> There's a proposal for C2y to use goto labels as loop names, and a
>>> competing one to define a new syntax like "for NAME (;;)" :
>>>
>>> https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3355.htm
>>> https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3377.pdf
>>
>> I'm not particularly a fan of multi-level break/continue. But if
>> we're going to have one of these, the second ("for NAME (;;)") is
>> unquestionably better.
>
> Unquestionably? Why?
>
> I do like the fact that it doesn't conflate goto labels with loop
> names, but I still prefer the "NAME: for (;;)" form, partly because
> it's consistent with several other languages.
If a loop has a statement label, traditionally usable with goto,
and we allow it to be used with a break, that is still a "goto label".
The break is a kind of goto, and the named break is a goto-like transfer
whose target is found with the help of the label, just a little
differently from goto. It goes past the labeled statement, essentially.
It's a "goto-adjacent operation" or "close sibling of goto".
It could be generalized such that if there is a labelled statement
"L: S" in the function scope, then "break X" anywhere in the function
can be used anywhere in the function to jump to that abstract point
where control ends up immediately after the execution of S.
In other words, supposed things were as if L: S had the meaning
L: { S; __L_after :; } and "break L;" with a label argument then
has the meaning "goto __L_after". Except that there is no such
code transformation; the target of "break L" is an abstract point
relatie to the statement labeleld by L without any invisible
auxilirary derived label.
Then there would be complete consistency: the scope of L would be
the same regardless of whether it is used as a break or goto target,
and L would be acting as a control transfer destination in both
uses, disparaging all traces of a conflation.
Now imagine that we have this design and we don't like that
a break can transfer past a labelled statement from anywhere
in a function.
We can then add the constraint that a "break L" statement is
required to be located inside the statement labelled by L.
That does not change the scope; it's just a constraint. A "break L"
outside of that statement is understood perfectly well as referring to
unambiguously that L, but required to be diagnosed. (Could be readily
supported as an extension.)
--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
Technical Details
Message-ID:
<20261019162536.783@kylheku.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.twilightnode.org!sklaffkom!eternal-september.org!feeder.eternal-september.org!nntp.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> <11ae7eb$cjlv$6@dont-email.me> <11aeee0$24k8m$1@kst.eternal-september.org> <11aer17$286ml$2@dont-email.me> <11aeusp$29hmu$2@kst.eternal-september.org> <86mrsdpcgp.fsf@linuxsc.com> <11au6pr$3mdne$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!news.twilightnode.org!sklaffkom!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Kaz Kylheku <046-301-5902@kylheku.com> Newsgroups: comp.lang.c Subject: Re: Taming The Switch-Statement Date: Mon, 19 Oct 2026 23:41:30 -0000 (UTC) Organization: A noiseless patient Spider Lines: 67 Message-ID: <20261019162536.783@kylheku.com> 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> <11ae7eb$cjlv$6@dont-email.me> <11aeee0$24k8m$1@kst.eternal-september.org> <11aer17$286ml$2@dont-email.me> <11aeusp$29hmu$2@kst.eternal-september.org> <86mrsdpcgp.fsf@linuxsc.com> <11au6pr$3mdne$1@kst.eternal-september.org> Injection-Date: Mon, 19 Oct 2026 23:41:31 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2652611"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+hIYmBfGivhdAagVyeu+BRrthXM5QoFhA="; posting-host="5346d2c78a55fce268e448ad5f69f603" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:viBxqoFPwlnGXmJGdzv0eAHrqsg= sha256:AwEyV+zV6V2sXRQb+Brka7jAbIhUN3Dr++qzu/VFIfM= sha1:9bMFTqcnbihterZlTXx6QHLIevM= sha256:A4jdc2t4rGIz+OHvMRGs9dmSyQb7KaeMA6k+ZMXIV9U=