Article View: comp.lang.c
Article #542Re: Taming The Switch-Statement
From: Keith Thompson
Date: Mon, 19 Oct 2026 10:50
Date: Mon, 19 Oct 2026 10:50
55 lines
4011 bytes
4011 bytes
David Brown <david.brown@hesbynett.no> writes:
[...]
> I can appreciate wanting a syntax that is distinct from regular labels
> for "goto".
So can I. The first language I used that had this kind of thing
was Ada. In the language's initial design, it was decided that
though goto statements were needed, the labels should stand out:
<<LABEL>>
-- ...
goto LABEL;
Names used for loops have a lighter-weight syntax:
LOOP_NAME:
while condition loop
-- ...
end loop;
I can't think of a better syntax for loop names than "NAME:" (used
by several other languages), but in C that syntax is already
taken for goto labels. The possibility of any ambiguity between
"goto NAME;" and "break NAME;" doesn't bother me enough to want
to invent something new. And I consider the fact that other
languages use the "NAME:" syntax for loop names to be another
point in its favor.
The odd scoping rules for labels don't bother me either. They mean
you can't have two loops or switch statements with the same name in
the same function. I can barely imagine that being inconvenient.
And it's already specified in the latest C2y draft, and implemented in
gcc and clang, which means there's already some inertia against any
major changes. Anything could happen between now and the publication
of the next C standard, but I don't see any need to make significant
changes in this area.
I use Perl's equivalent of named break quite a lot. I found
31 occurrences of "exit NAME" in a collection of Perl scripts
I've written. I'm a little surprised to find that none of these
break out of nested loops; I just like to name loops for clarity.
I even find that having to choose a name for something forces
me to think more clearly about it.
The C2y proposed syntax and semantics for named loops and switch
statements is of course imperfect, but it's reasonably clean
and useful. I see no need to make any significant changes in
this area.
[...]
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Technical Details
Message-ID:
<11b4smj$1vt4q$1@kst.eternal-september.org>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!kst.eternal-september.org!.POSTED!not-for-mailReferences:
<119qf6l$2rmg3$1@dont-email.me> <20261010220212.000063fd@yahoo.com> <11ae56o$cjlv$4@dont-email.me> <20261010230355.00005189@yahoo.com> <11ae7eb$cjlv$6@dont-email.me> <11aeee0$24k8m$1@kst.eternal-september.org> <11aer17$286ml$2@dont-email.me> <11aeusp$29hmu$2@kst.eternal-september.org> <86mrsdpcgp.fsf@linuxsc.com> <11au6pr$3mdne$1@kst.eternal-september.org> <11auc0s$206gh$3@dont-email.me> <11b285v$121v2$2@dont-email.me> <11b293j$12jfa$1@dont-email.me> <11b2cuh$141vj$1@dont-email.me> <11b2eck$3pvd9$1@dont-email.me> <20261018171339.00005308@yahoo.com> <11b2mf1$16mof$2@dont-email.me> <20261018181623.00007978@yahoo.com> <11b347h$1cn63$1@dont-email.me> <20261018223859.000031d3@yahoo.com> <11b4n4s$1q18k$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!kst.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson <Keith.S.Thompson+u@gmail.com> Newsgroups: comp.lang.c Subject: Re: Taming The Switch-Statement Date: Mon, 19 Oct 2026 03:50:56 -0700 Organization: None to speak of Lines: 55 Message-ID: <11b4smj$1vt4q$1@kst.eternal-september.org> References: <119qf6l$2rmg3$1@dont-email.me> <20261010220212.000063fd@yahoo.com> <11ae56o$cjlv$4@dont-email.me> <20261010230355.00005189@yahoo.com> <11ae7eb$cjlv$6@dont-email.me> <11aeee0$24k8m$1@kst.eternal-september.org> <11aer17$286ml$2@dont-email.me> <11aeusp$29hmu$2@kst.eternal-september.org> <86mrsdpcgp.fsf@linuxsc.com> <11au6pr$3mdne$1@kst.eternal-september.org> <11auc0s$206gh$3@dont-email.me> <11b285v$121v2$2@dont-email.me> <11b293j$12jfa$1@dont-email.me> <11b2cuh$141vj$1@dont-email.me> <11b2eck$3pvd9$1@dont-email.me> <20261018171339.00005308@yahoo.com> <11b2mf1$16mof$2@dont-email.me> <20261018181623.00007978@yahoo.com> <11b347h$1cn63$1@dont-email.me> <20261018223859.000031d3@yahoo.com> <11b4n4s$1q18k$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Mon, 19 Oct 2026 10:51:00 +0000 (UTC) Injection-Info: kst.eternal-september.org; logging-data="2094234"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/cr7ecOlA5DVEJkxQgDyq/"; posting-host="9660475a9289184964a5dc25cbc4aed9" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:wCHHBqaTP8e9OTBpg6d7gDab2sA= sha256:gdwcfj/Q9rOj+3lbp7+6bCykbBvTQn44rVFMJ4QDJPs= sha1:395r90wkyUKug48SlXCvJNuc+50= sha256:MgHFV2nMyadNcgKaBChZ6zRdk5YFj51V3fc+OzEEb+8=