Article View: comp.lang.c
Article #242Re: Taming The Switch-Statement
From: bart
Date: Sun, 11 Oct 2026 22:02
Date: Sun, 11 Oct 2026 22:02
56 lines
3893 bytes
3893 bytes
On 11/10/2026 22:28, Keith Thompson wrote: > bart <bc@freeuk.com> writes: > [...] >> 'break' to quit a loop early is part of the language, so why shouldn't >> someone make use it? > > Agreed. (There are coding styles that require loops to exit only at the > bottom, but that's not what we're talking about.) > >> It just its use can be interfered with when 'switch' is involved. > > Yes. Everyone here knows that, and knew it before you started talking > about it. > > Michael S wrote above that "The cases where I want to break out of > the loop from the switch in the body of the loop are very common." > Tim Rentsch questioned the "very common" part of that, and asked > for an example. You jumped in and asserted that an example isn't > necessary, because you misunderstood what was being said. *Of > course* there are cases where someone might want to break out of > a loop from a nested switch. You're missing the undercurrent, which is a tone of disapproval and disbelief. But we'll find out if and when examples are ever posted. However you may want to consider that examples are rare, or even non-existent, /because/ it's not possible to do! So using 'switch' is avoided or some other workaround is found. Michael S actually said this: "The cases where I want to break out of the loop from the switch in the body of the loop are very common." This expresses a desire to do so. > Breaking out of an outer loop from within an inner loop is just > as much of a problem. A less common one but when it happens it will be an actual problem and not an artificial one. > "break NAME;" proposed for C2y, would solve > both problems. (I just found out that recent versions of gcc and > clang support this as an extension or with "-std=c2y".) OK. I'd rather have a solution that doesn't involve inventing names. Does this also fix the break-out-of-a-loop-from-inside-switch issue? In that case just 'break for/while' might do! You know, a little bit like using a different keyword for loops/non-loops.
Technical Details
Message-ID:
<11ah12b$320sj$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-mailReferences:
<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>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: Sun, 11 Oct 2026 23:02:53 +0100 Organization: A noiseless patient Spider Lines: 56 Message-ID: <11ah12b$320sj$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> <11agv1t$30q22$2@kst.eternal-september.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 11 Oct 2026 22:02:52 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3212179"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18kPGMw9eoe6zzRhAMVE/Fh"; posting-host="bb4c63ed27c528dcfc498e66a186f254" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:0uReJm75ljU4wwB/s9o8GvTQpiQ= sha256:KDy9dVlfLvHAe29JjfvSt3zZXjKsxp80Jf2bTSQXVBA= sha1:5rFb2Me4dwICj2SawUAnTnNrryc= sha256:0r9iUpjAriEv0+lymCYbZLs4Cq/kH0nZdPhaXvgjMFA= Content-Language: en-GB In-Reply-To: <11agv1t$30q22$2@kst.eternal-september.org>