🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #267

Re: Taming The Switch-Statement

#267
From: bart
Date: Mon, 12 Oct 2026 15:32
90 lines
5140 bytes
On 12/10/2026 15:12, David Brown wrote:
> On 12/10/2026 15:37, bart wrote:

> That is obviously a silly, invented example.

Yes, but I am not discussing that in this post. The subthread is 
switch-break interfering with loop-break.


>>
>> The loop body shows two ways of aborting the loop when an exit 
>> condition is detected:
>>
>> * Using an if-statement and 'break'
>>
>> * Using a switch-statement and ... break?
>>
>> The second doesn't work because 'break' now shadows its outer meaning. 
>> Both would otherwise be reasonable choices for this logic.
> 
> No, they would not be reasonable choices.

Why not? You seem to be talking about both IF and SWITCH here; are there 
any other conditional control-flow statements that I'm not aware of?

Or is your more reasonable approach involving superfluous loops or 
superfluous functions (just to score some point)?

We're trying to avoid convoluted code.

>  It is very, /very/ simple, as 
> long as your code is written in a structured manner - nesting the 
> constructs as you did above.  "break" applies to the innermost loop or 
> switch.  That's the rule.

Yes, we know that's rule! And that is the problem: the break of switch 
interferes with normal loop break, which means that forces your hand 
whenever you'd prefer to use the more apt 'switch' construct.

>> This is valid C still, but it doesn't have the same behaviour.
> 
> Surprise!  Someone changed the code, and the behaviour changed!  Who 
> could have imagined that might happen?

Now you're being facetious. THE BEHAVIOUR SHOULD BE EXACTLY THE SAME:

     Loop
        ....
        Break when some condition is true
        ....

You should be able to choose how you write your conditions. So the fact 
that the behaviour changes while expressing the same logic IS THE PROBLEM.

I mean, why on earth should it? Just because some numskull decided to 
use the same fucking keyword for two different things?

Now, everyone is trying to suggest it was in fact a wonderful idea, you 
save one whole keyword, and that it's SO easy to try and avoid the 
ensuing mess by programming your way around it or avoiding certain 
statement combos.


>> In my language and in my programs,
> 
> No one else cares.  Your language is your own, and not relevant outside 
> of your bubble.  You keep thinking it somehow "proves" your points, or 
> that it shows how "wrong" C is - it does not.

Then you've just got your head in the sand, sorry.

People have been asking about examples of exiting a loop from within 
switch, and in my code there are myriad such examples, even more than 
I'd thought (I guess I don't even think about it).

That they're in a different language doesn't matter: it shows the idiom, 
that code-pattern, can be useful and can be the more natural and 
intuitive choice.

Of course you won't find such examples in C because the language doesn't 
allow it!

Oh, and I also showed an easy solution to the nested loops issue.


>  There is no need to waste 
> your time or other readers' time by writing about it.  Stick to writing 
> about C here.
The subject is Taming the Switch-Statement, and the opening post was 
ways to forget writing that famous 'break'.
Technical Details
Message-ID: <11aiui8$3nisn$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> <11ag37o$2ln0a$1@dont-email.me> <11agbsh$2pbk7$1@dont-email.me> <11aggaq$2qqh9$1@dont-email.me> <11agils$2s3tg$1@dont-email.me> <11ahpqi$38ir0$2@dont-email.me> <11ainqf$3kkvd$1@dont-email.me> <11aipsc$3kr94$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: bart <bc@freeuk.com>
Newsgroups: comp.lang.c
Subject: Re: Taming The Switch-Statement
Date: Mon, 12 Oct 2026 16:32:25 +0100
Organization: A noiseless patient Spider
Lines: 90
Message-ID: <11aiui8$3nisn$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> <11ag37o$2ln0a$1@dont-email.me>
 <11agbsh$2pbk7$1@dont-email.me> <11aggaq$2qqh9$1@dont-email.me>
 <11agils$2s3tg$1@dont-email.me> <11ahpqi$38ir0$2@dont-email.me>
 <11ainqf$3kkvd$1@dont-email.me> <11aipsc$3kr94$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 12 Oct 2026 15:32:25 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="3918743"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18FAMmaSMci9DT7vThlaBmY"; posting-host="77c9fe16ce3505b18aae67dd9ba4b8ee"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Q5xsjRpZBKUdNd46a+nfuPkjAqs= sha256:jmc51HmlaHb8nlslZZTuOnr/DLEp81+ohHNS0tYouZg=
	sha1:1bFCXxA8CNIkxNjWP2ZSj+h2fRo= sha256:vrWAHXc39Ibce4e+mLSh6oglkqttdKFz2pgBObmeFS8=
Content-Language: en-GB
In-Reply-To: <11aipsc$3kr94$1@dont-email.me>