🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #252

Re: Taming The Switch-Statement

#252
From: Waldek Hebisch
Date: Sun, 11 Oct 2026 23:38
25 lines
2370 bytes
Lawrence D’Oliveiro <ldo@nz.invalid> wrote:
> On Sun, 11 Oct 2026 05:52:51 -0000 (UTC), Waldek Hebisch wrote:
> 
>> AFAICS Pascal-style 'case' + 'goto' that can jump inside constructs
>> can do everthing C 'switch' can do.
> 
> There is an interesting result known as the “Structure Theorem”, which
> proves that any kind of control structure can be implemented by
> putting your entire program inside a large switch-statement within a
> loop and using state variables to control which path is taken each
> time round the loop -- with no gotos anywhere!
> 
> Of course, since it can be hard to discern the relationship between
> one switch-branch being executed on one loop iteration and whatever
> switch-branch is entered on the next iteration, the result is still a
> form of spaghetti code ...

Unlike structure theorem the above does not need extra state variable.

BTW: Good compiler should be able to eliminate state varible and
recreate original spagetti, but no compiler that I use is good
enough.

-- 
                              Waldek Hebisch
Technical Details
Message-ID: <11ah6ll$1pjp4$1@paganini.bofh.team>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!newsfeed.bofh.team!paganini.bofh.team!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> <11admri$1s1lb$1@dont-email.me> <11af87h$1m4em$1@paganini.bofh.team> <11aguaq$30k5e$4@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!newsfeed.bofh.team!paganini.bofh.team!not-for-mail
From: antispam@fricas.org (Waldek Hebisch)
Newsgroups: comp.lang.c
Subject: Re: Taming The Switch-Statement
Date: Sun, 11 Oct 2026 23:38:31 -0000 (UTC)
Organization: bofh.team Usenet service
Message-ID: <11ah6ll$1pjp4$1@paganini.bofh.team>
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> <11admri$1s1lb$1@dont-email.me> <11af87h$1m4em$1@paganini.bofh.team> <11aguaq$30k5e$4@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Oct 2026 23:38:31 -0000 (UTC)
Injection-Info: paganini.bofh.team; logging-data="1888036"; mail-complaints-to="usenet@bofh.team"; posting-host="d028f9ad2fa2c51f22dbfed0d81d7daf"; posting-account="69e66f1681224ab92235b464ce7a90b6"
User-Agent: tin/2.6.2-20221225 ("Pittyvaich") (Linux/6.1.0-9-amd64 (x86_64))
X-Postfilter: Postfilter-NG 2026.10.2