🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #214

Re: Taming The Switch-Statement

#214
From: David Brown
Date: Sun, 11 Oct 2026 13:33
44 lines
3384 bytes
On 11/10/2026 14:35, bart wrote:
> On 11/10/2026 12:26, Tim Rentsch wrote:
>> Michael S <already5chosen@yahoo.com> writes:
>>
>>> The cases where I want to break out of the loop from the switch in
>>> the body of the loop are very common.
>>
>> That surprises me.  Can you post a representative example (and
>> ideally not overly long)?
> 
> 
> An example shouldn't be necessary. It is enough to know that loop-breaks 
> exist and are used.
> 
> Then, whether break works here:
> 
>     while (cond) {
>          ....
>          break;
>          ....
>     }
> 
> shouldn't need to depend on whether that break happens to be inside a 
> switch statement.
> 
> Maybe it is within an if-else chain, but at some point it is refactored 
> into a switch statement. Now it no long does what is expected, and in 
> fact using break to quit the loop from inside switch becomes impossible.
> 

The question was not about how it is possible to write a loop within a 
switch and have a "break" statement inside the loop.  The question was 
about how often such code was written, and what makes it "very common" 
for Michael.  I am also curious to know if he finds the use of the same 
"break" keyword makes the code more difficult to read, or increases the 
risk of errors or misunderstandings.

It is quite obvious that it is easy to write code with loops + break 
within a switch.  It is equally obvious that it is easy to avoid such 
constructs - there are always ways to avoid a "break" in a loop, and if 
the code run within a switch case is complex, it is often practical to 
refactor it into a separate function.  But presumably Michael has 
reasons not do do that.
Technical Details
Message-ID: <11ag37o$2ln0a$1@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>

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: Sun, 11 Oct 2026 15:33:44 +0200
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <11ag37o$2ln0a$1@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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Oct 2026 13:33:45 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="2808842"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/IBTe/tdImmzMOYYiMAEnYIu4cY7PTEnA="; posting-host="10283a9df1f0548a34352f02c4ddf11b"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:e9emlnd4ANcdmQ+UqzKdYHy9HsI= sha256:hVZn82G+R3Sc8lVf8n7AFKM4ROp2r+kNxhdjDYONiJ4=
	sha1:PasG6kOXjG/QN3om/8c2FBpS/s4= sha256:fgm4Ux80qn3Htry9GdTe7NiIqyZUGteq6fKuU3xJ6zs=
In-Reply-To: <11afvqt$2kloc$1@dont-email.me>
Content-Language: en-GB