🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #289

Re: Taming The Switch-Statement

#289
From: Janis Papanagnou
Date: Mon, 12 Oct 2026 20:32
62 lines
5185 bytes
On 2026-10-12 21:31, Michael S wrote:
> On Mon, 12 Oct 2026 21:09:25 +0200
> David Brown <david.brown@hesbynett.no> wrote:
>>> [...]
>>
>> If I have misunderstood, I would love to be corrected.  In a number
>> of my posts I said I was not sure what you were talking about, and
>> would need more explanation.
> 
> I thought that my comment is hard to misunderstand, but you proved
> me wrong. So I'd try to elaborate:
> 
> switch() nested within loop is very common in my practice and I suppose
> in practice of everybody else.

Something on a level like that was that I recall you had originally
written. So this doesn't explain more than your original statement
about that. It is quite clear (and I'm positive that it's as clear
to David). As far as I'm concerned, and that was how I understood
David's question, I'd (also) be (but only mildly!) interested what
the *concrete* _application cases_ those actually are since they (as
you said) appear so dominantly in your C-programs. Not the technical
structure ("for() switch() break;") but which types of applications
or application-semantical code patterns would require those that it
appears so often in your context. - My own interest here is limited,
as said, since it certainly doesn't apply to my C-code, and I never
noticed that it would be predominantly a prominent pattern in others'
C-code, beyond being one specific C-patterns amongst hundreds other
common C-patterns. - If it were extraordinarily common in your case
I'd indeed have thought about employing some standard pattern as a
substitute (see one of I think Dan's recent posts), and as you also
confirmed in this post - I snipped it - to actually have done this.

I hope that clarifies what some readers felt was missing.

Myself I also think that both, switch()-loop() and loop()-switch(),
constructs are just _corner-cases_ where doubling the 'break' could
help people, but it wouldn't at all address the more general tasks,
where e.g. more than just one loop and switch is nested.[*] - Myself
I'd certainly expect a solution that is more generally applicable;
labelled control-constructs are one way, even numbered breaks would
be an IMO acceptable extension. - But "C" only supports a one-level
local 'break' and a non-local flexible/arbitrary 'goto'. Two distinct
breaks would just pollute the name-space and not address the inherent
and basic restriction of being still just one-level breaks. - And I'm
confident that even then there'd pop up some pathological person and
complain about these breaks addressing not more that one levels.

Janis

[*] Note the many conditions we have here; exactly two specific and
different constructs, exactly two and not one or more than two, and
the case that you want to leave not one but both. - Can you imagine
that folks are wondering about what application context that stems
from that it appears so often (in your domain). - I think that was
the question that David had. It was certainly the question that
manifested in my mind when I read your post; only that I'm not too
much interested about it if you're operating in a domain where that
is more common than usual (and also don't bother to answer that).

> [...]
Technical Details
Message-ID: <11ajg4d$286mm$5@dont-email.me>
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!.POSTED!not-for-mail
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> <11agv1t$30q22$2@kst.eternal-september.org> <20261012220256.00003d07@yahoo.com> <11ajb95$3t8jj$1@dont-email.me> <20261012223144.00000f95@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!.POSTED!not-for-mail
From: Janis Papanagnou <janis_papanagnou+ng@hotmail.com>
Newsgroups: comp.lang.c
Subject: Re: Taming The Switch-Statement
Date: Mon, 12 Oct 2026 22:32:13 +0200
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <11ajg4d$286mm$5@dont-email.me>
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> <11agv1t$30q22$2@kst.eternal-september.org>
 <20261012220256.00003d07@yahoo.com> <11ajb95$3t8jj$1@dont-email.me>
 <20261012223144.00000f95@yahoo.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 12 Oct 2026 20:32:13 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2366166"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19URsQxftpIqhU2Lt/L0Fxz"; posting-host="5867007c58404d9809ba59751570602e"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:tUk1McBymNZe+TZF5SFPSgqQER4= sha256:2skcKQn9AlmJiSdtPamAcsurF5l1iilF+ODgRqPfE4I=
	sha1:MH2DIqYxMpR/EMgdz8PlZEda8hw= sha256:VUKBo9wpcjaz6Z2GEBXqDroavM/4l+75y81MtAC7Zmk=
Content-Language: en-US
In-Reply-To: <20261012223144.00000f95@yahoo.com>