🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #526

Re: Taming The Switch-Statement

#526
From: Dan Cross
Date: Sun, 18 Oct 2026 22:18
53 lines
3590 bytes
In article <11b2pq5$3pvda$7@dont-email.me>,
Janis Papanagnou  <janis_papanagnou+ng@hotmail.com> wrote:
>On 2026-10-18 16:13, Michael S wrote:
>> 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.
>
>I can see that this might look appealing in case of 'break'. In
>case of the same mechanism working also for 'continue' I'd then
>think that it should generally better be an "attribute" of the
>loop entry keyword, i.e. placed where loops start. (But that's
>just my opinion.) Having it at a different place with a do-loop
>I consider a really bad decision. It's advantageous to know the
>direction in which to seek for the label if you inspect code. -
>But okay, it's "C"; I won't heat up about some future C-release
>that I'll never use (especially given that I'm not even be using
>all of those more recent additions that are already available).

I think colocating it with `do` might create a syntactic
ambiguity.  In the case of `for`, `while`, and `select`, there
is a required token following the keyword (the `(`).  However,
for a `do`/`while` loop, `do` is followed immediately by a,
`secondary-block` production.  In particular, you do not _need_
braces to denote a compound statement after `do`; something like
`do i++; while (i < j);` is perfectly legal in C.

In the N3377 proposal, the new `block-name` is just an
identifier.  If it were allowed immediately after the `do`, then
given, `do NAME statement; while(condition);` you can't tell
`NAME` from the name of the loop and a random identifier before
a statement; something like `do LOOP i++; while (i < j);`
appears as though it _would_ be be syntactically valid by N3377
as presently worked, but is the programmer's intent to create a
loop name, or should this just be a syntax error?

By requiring the block-name between a keyword and a
syntactically required `(`, you remove that ambiguity: if there
is an identifier there, then it is a `block-name`; if not, then
the block has no name.

	- Dan C.
Technical Details
Message-ID: <11b3gkj$mt2$1@reader2.panix.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!panix!.POSTED.spitfire.i.gajendra.net!not-for-mail
References: <119qf6l$2rmg3$1@dont-email.me> <11b2eck$3pvd9$1@dont-email.me> <20261018171339.00005308@yahoo.com> <11b2pq5$3pvda$7@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!panix!.POSTED.spitfire.i.gajendra.net!not-for-mail
From: cross@spitfire.i.gajendra.net (Dan Cross)
Newsgroups: comp.lang.c
Subject: Re: Taming The Switch-Statement
Date: Sun, 18 Oct 2026 22:18:59 -0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <11b3gkj$mt2$1@reader2.panix.com>
References: <119qf6l$2rmg3$1@dont-email.me> <11b2eck$3pvd9$1@dont-email.me> <20261018171339.00005308@yahoo.com> <11b2pq5$3pvda$7@dont-email.me>
Injection-Date: Sun, 18 Oct 2026 22:18:59 -0000 (UTC)
Injection-Info: reader2.panix.com; posting-host="spitfire.i.gajendra.net:166.84.136.80";
	logging-data="23458"; mail-complaints-to="abuse@panix.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: cross@spitfire.i.gajendra.net (Dan Cross)