Article View: comp.lang.c
Article #167Re: Taming The Switch-Statement
From: Janis Papanagnou
Date: Sun, 11 Oct 2026 01:58
Date: Sun, 11 Oct 2026 01:58
35 lines
3427 bytes
3427 bytes
On 2026-10-11 00:30, Andrey Tarasevich wrote: > On Sat 10/10/2026 1:33 PM, Janis Papanagnou wrote: >> On 2026-10-10 22:03, Michael S wrote: >>> >>> The cases where I want to break out of the loop from the switch in the >>> body of the loop are very common. >> >> Ah, so you'd have needed something like Kornshell's 'break 2' to leave >> more than one level. > > Yes, but that would be rather inelegant in the overall scheme of things > in C, since once we start talking about `break 2` it would be logical to > consider `continue 2` as well (i.e. like Kornshell's `continue`). > > But `break` and `continue` behave differently inside `switch` in C: the > former can "see" the enveloping `switch` statements, while for the > latter all enveloping `switch` statements are completely transparent. > So, in order to refer to the same cycle one'd have to use different > nesting numbers in `break` and `continue` when used inside `switch`(-es) > in C. That would look quite confusing. Personally I don't like jumps in programming at all, but sometimes a break is clearer than embedding a boolean into a surrounding control structure and keeping explicitly track of the exit state value. Even less I like a 'goto'; the one case where I find it worthwhile, to jump from within nested loops to the continuation point after the nested loops, is not something I like, but I also only very rarely needed it and I wouldn't mind using it. Similar with the 'break N' and 'continue N' in Kornshell; I would be surprised if I had used it more than once or at most twice in decades. - I'm generally using what the languages provide and what is best maintainable. - As I see it there's no single perfect way how to address that issue. YMMV. Janis
Technical Details
Message-ID:
<11aeqfh$286mm$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> <11ae7eb$cjlv$6@dont-email.me> <11aeeau$24vgh$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: Janis Papanagnou <janis_papanagnou+ng@hotmail.com> Newsgroups: comp.lang.c Subject: Re: Taming The Switch-Statement Date: Sun, 11 Oct 2026 03:58:09 +0200 Organization: A noiseless patient Spider Lines: 35 Message-ID: <11aeqfh$286mm$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> <11ae7eb$cjlv$6@dont-email.me> <11aeeau$24vgh$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 11 Oct 2026 01:58:10 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2366166"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/m2hbePyMwyfTYR72uiHKp"; posting-host="dc047fa64def26b023d01b53ecdcc125" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:iWlRBRLgBv4HWWTwe2hoO9Iafpw= sha256:OzTsVTtH3ku+4MeycNRt8V5O97ZTIpsYHOmtQUOAvg4= sha1:Ez+skOqu+DmKuA22LMSU7hZOmBE= sha256:WjyzuP+/ex64dxLrQdpaUOPlvasYMOsbwu5oSB6KuBs= In-Reply-To: <11aeeau$24vgh$1@dont-email.me> Content-Language: en-US