Article View: comp.lang.c
Article #532Re: Taming The Switch-Statement
From: Keith Thompson
Date: Mon, 19 Oct 2026 01:33
Date: Mon, 19 Oct 2026 01:33
58 lines
3861 bytes
3861 bytes
Michael S <already5chosen@yahoo.com> writes:
> On Sun, 18 Oct 2026 14:34:28 +0200
> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
>> On 2026-10-18 14:09, David Brown wrote:
>> >
>> > [...] (I don't know why N3377 proposed "do { } while NAME ( )"
>> > rather than "do NAME { } while ( )". )
>>
>> Oh! - I can only think that it would then be (sort of) "consistent"
>> with the place of the label attacked in a 'while' loop; i.e. behind
>> the 'while' keyword. - It's inconsistent in another interpretation,
>> though; and I'd certainly have favored the latter form, to have the
>> label consistently attached at the loop-entry keyword.
>
> I'd prefer label consistently attached to the loop-exit keyword.
> Unfortunately, for() and while() loops have no such keyword.
I see your point, but I disagree.
Let's say we have a language where the end of a loop is marked by a
keyword.
WHILE condition
statement;
statement;
ENDWHILE;
Now we want to add the ability to break out of a specified loop,
possibly from within a nested construct. With your preference:
WHILE condition
statement;
if (error) break OUTER; ENDIF;
statement;
OUTER: ENDWHILE;
Putting the label at the bottom of the loop does show more clearly
the point in the code to which the "break" transfers control. In my
opinion, that's not a good thing.
With the label name at the top:
OUTER:
WHILE condition
statement;
if (error) break OUTER; ENDIF;
statement;
ENDWHILE;
"OUTER" is *the name of the loop*, and the entire loop is the
construct to which "break OUTER" applies.
If the syntax emphasizes the point to which the break jumps, I
don't see much advantage over goto.
--
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:
<11b3s0v$1lao8$1@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> <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> <11auc0s$206gh$3@dont-email.me> <11b285v$121v2$2@dont-email.me> <11b293j$12jfa$1@dont-email.me> <11b2cuh$141vj$1@dont-email.me> <11b2eck$3pvd9$1@dont-email.me> <20261018171339.00005308@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: Sun, 18 Oct 2026 18:33:19 -0700 Organization: None to speak of Lines: 58 Message-ID: <11b3s0v$1lao8$1@kst.eternal-september.org> References: <119qf6l$2rmg3$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> <11auc0s$206gh$3@dont-email.me> <11b285v$121v2$2@dont-email.me> <11b293j$12jfa$1@dont-email.me> <11b2cuh$141vj$1@dont-email.me> <11b2eck$3pvd9$1@dont-email.me> <20261018171339.00005308@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Mon, 19 Oct 2026 01:33:20 +0000 (UTC) Injection-Info: kst.eternal-september.org; logging-data="1747720"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19FerB058w1lwdBWm0QL3BN"; posting-host="9660475a9289184964a5dc25cbc4aed9" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:gG2RrYorVRoJVDB3simG0MTrqKA= sha256:+x1oUFnA7AS4RqYDYuwb6VkN3oOlRk63Eh8RcExEbsY= sha1:nkaQ3RpPtcXLZK2tag/SC4G9bzI= sha256:lJOUtslRy1GjY/ZsTS5/tpVTtPZCwyAntREQG0KmODg=