Path: csiph.com!weretis.net!feeder9.news.weretis.net!panix!.POSTED.spitfire.i.gajendra.net!not-for-mail From: cross@spitfire.i.gajendra.net (Dan Cross) Newsgroups: comp.lang.c Subject: Re: Taming The Switch-Statement Date: Wed, 14 Oct 2026 19:47:22 -0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Message-ID: <11aom8a$6sa$1@reader2.panix.com> References: <119qf6l$2rmg3$1@dont-email.me> <11anobe$1dt0e$1@dont-email.me> <11ant3u$6o$1@reader2.panix.com> <11aoff0$1n82v$1@dont-email.me> Injection-Date: Wed, 14 Oct 2026 19:47:22 -0000 (UTC) Injection-Info: reader2.panix.com; posting-host="spitfire.i.gajendra.net:166.84.136.80"; logging-data="7050"; mail-complaints-to="abuse@panix.com" X-Newsreader: trn 4.0-test77 (Sep 1, 2010) Originator: cross@spitfire.i.gajendra.net (Dan Cross) Xref: csiph.com comp.lang.c:403163 In article <11aoff0$1n82v$1@dont-email.me>, bart wrote: >On 14/10/2026 13:38, Dan Cross wrote: >> In article <11anobe$1dt0e$1@dont-email.me>, bart wrote: > >> Yes, I am aware that you will tell me that it is justified >> because that problem is actually the one worth solving, and the >> others are not; you needn't bother. Simply put, I disagree that >> that one problem is sufficiently important to warrant its own >> solution, particularly when something more general is already >> known and available in the language (labeled break/continue). > >I missed this bit. > >Is labeled break now available in C? It's in C2y, and has been implemented in (at least) LLVM/clang and GCC. I don't know about other compilers. >If so, how would it be used here: > > > while (1) { > switch (x) { > case y: > Break; > >where that Break is meant to quit the loop. term% cat lb.c #include int main(void) { int sum = 0; outer: for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { int p = i * j; switch (p) { case 500: break outer; default: sum += p; break; } } } printf("sum = %d\n", sum); return 0; } term% clang-23 -std=c2y -o lb lb.c term% ./lb sum = 235000 term% gcc-16 -std=c2y -o lb lb.c term% ./lb sum = 235000 term% sed 's/outer./\;/' lb.c >lb2.c term% clang-23 -std=c2y -o lb2 lb2.c term% ./lb2 sum = 24500500 term% >Remember that if DMR hadn't made that screw-up in 1972 it would simply >have been as it is above with his choice of keyword in place of Break. As I said in my other post, you incorrectly assume that that was the fundamental issue, when really it's just a detail: the problem was that no facility to break out of nested control structures as provided. Remedied now! >But I would be interested in trying out the new feature. So do it. You don't need me to hold your hand. - Dan C.