🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #277

Re: Taming The Switch-Statement

#277
From: bart
Date: Mon, 12 Oct 2026 18:15
66 lines
4195 bytes
On 12/10/2026 18:05, David Brown wrote:
> On 12/10/2026 17:32, bart wrote:

>>>> 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?
> 
> I am sure you have read the C standards, so that you know the answer to 
> that.

I still don't know what you mean. So, using 'if' for conditional exit 
from a loop is unreasonable. But so is 'switch', even putting aside the 
issue with break.

It seems to me that you are just gaslighting now.

>> Yes, we know that's rule! 
> 
> So we are done, then?  One simple rule to learn - and a pretty obvious 
> rule at that.  Now you know the answer, you can stop worrying about it.

What? Having a stupid rule in place doesn't mean it hasn't caused issues!


>> 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.
> 
> There is no interference.  There is a /limitation/ - "break" only exits 
> the innermost structure, and cannot break out of outer structures.  It's 
> like "return" only returns from the current function, not the function 
> that called it.

It's a good thing that they didn't choose to use 'return' for both loop 
exit and switch-break then!

But if they had:

* You couldn't use early return from inside a loop

* Nor from inside a switch

* You still couldn't exit early from a loop from inside switch

* 'return' would do three different things depending on context,
   but none interfere with each other

Obviously this wouldn't be a problem for you either? After all that 
would be the rule, still a fairly simple one. And it would have saved 
one more keyword which is really, really important.

Yeah, I think now we're done.

Technical Details
Message-ID: <11aj844$3rt9c$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> <11aiui8$3nisn$1@dont-email.me> <11aj41i$3oq6i$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 19:15:30 +0100
Organization: A noiseless patient Spider
Lines: 66
Message-ID: <11aj844$3rt9c$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>
 <11aiui8$3nisn$1@dont-email.me> <11aj41i$3oq6i$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 18:15:33 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="4060460"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+x+JWtI1MxRck8MJiee6sL"; posting-host="77c9fe16ce3505b18aae67dd9ba4b8ee"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:jHH/EXWq7eOe0FJVHW5xHOAf8co= sha256:Qay3o/9VfQD/Zx/DRAAAvLAPGMl+wq/u7JQBlS3ETFg=
	sha1:lYJcqUdP3f5159BHMatljJxdV/4= sha256:TsE/UDDQbuiA0kqK2ev1vYKY99jbIdV3NSHgcxU2sqM=
Content-Language: en-GB
In-Reply-To: <11aj41i$3oq6i$1@dont-email.me>