🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #257

Re: Taming The Switch-Statement

#257
From: David Brown
Date: Mon, 12 Oct 2026 05:05
66 lines
4987 bytes
On 11/10/2026 19:57, bart wrote:
> On 11/10/2026 18:17, David Brown wrote:

>> Only Michael can, if he wants, explain what he was thinking.
> 
> It sounds like he's pressurised into doing so. Maybe so that he can be 
> lectured on how to it 'properly'.

The "pressure" is just because people are curious for more detail. 
Michael is an experienced C programmer, but we all work in slightly 
different ways on slightly different kinds of code bases.  I can't think 
why breaking out of loops within switch cases would be "very common", 
but I have no reason to suspect Michael was not writing code "properly". 
  I can't think why such code - common or not - would be problematic, or 
why having two different "break" keywords or constructs would be better 
for his code.  That's why I would like Michael to give more details - 
not to tell him his "wrong", but to learn more about his coding.

> 
> 'break' to quit a loop early is part of the language, so why shouldn't 
> someone make use it?

I think most C programmers do, at least occasionally.

> 
> It just its use can be interfered with when 'switch' is involved.
> 

I personally have never found an issue there.  "break" breaks out of the 
innermost loop or switch.  If you write switch statements that are 
intermingled with loops in a non-structured manner, I am sure things get 
difficult and unclear.  Since I do not write code with such 
intermingling, I have not had any such problems.  Other people may 
choose to intermingle switches and loops, and may then have issues as a 
result, but I have not seen this in real code.

> That that happens and needs a workaround, is not satisfactory. The issue 
> exists 100% because of sharing the 'break' keyword for two different 
> purposes.
> 

First, there is no indication that conflicts between switch and loop 
"break" occurs in real code, or what the nature of such issues are. 
(Michael's brief comments are not enough information.)  Secondly, there 
is no indication that this "needs a workaround" - especially as there is 
no definition of what might be called a "workaround".  Usually you use 
the term to mean C code that you want to complain about.  Thirdly, the 
keyword "break" is not being used for two different purposes - it is 
being used for the same purpose in two different control structures.

It is well established that there are occasions where you have nested 
control structures, where it would be useful to be able to break out of 
an outer structure.  In C, "break" by itself does not handle such cases, 
and thus additional code is needed (what you call a "workaround", and 
other people call "writing code") - something people have managed to do 
for decades.  It is well established that at least some programmers 
would find it convenient to have some kind of multi-level or labelled 
"break" to let such cases be handled in a neater way, and there are 
proposals to add such a feature to C.  This is a general situation with 
nested control structures, and not in any way specific to switches or 
mixes of switches and loops - almost certainly, nested loops are the 
primary use-case.



Technical Details
Message-ID: <11ahpqi$38ir0$2@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>

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: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.lang.c
Subject: Re: Taming The Switch-Statement
Date: Mon, 12 Oct 2026 07:05:22 +0200
Organization: A noiseless patient Spider
Lines: 66
Message-ID: <11ahpqi$38ir0$2@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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 12 Oct 2026 05:05:23 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="3427168"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19OWVjml8ZTBY+V9WmPlw97lL8AH4t07z4="; posting-host="711f10de653bed0662d2460037681553"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:sVeqPd2e0aEzmetHdubD+x+2B2Y= sha256:9ZCFsAhOrZLt/yAxtSiR/GuC5w2drrjoxlro43i8ZLs=
	sha1:H0EMt+Uu0mZ5QW+IuTHoMyR645A= sha256:iMx1UKBitD2B95aFOORqZaxYIbAqI3dyJjIq/C4WMfU=
Content-Language: en-GB, nb-NO
In-Reply-To: <11agils$2s3tg$1@dont-email.me>