Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Minimum amount of syntax for C language Date: Thu, 17 Nov 2016 11:56:03 -0800 Organization: None to speak of Lines: 44 Message-ID: References: <6963fc34-48b1-490f-b404-7ff4975b7780@googlegroups.com> <8d7b4901-003a-47d7-ab25-15d661da9f63@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="9e5c6cdd6c882157dc720953c941e742"; logging-data="5904"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19o37lSvfSDJFGAiASd2dO2" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:cvW+JJzrcoqxiI4SryP1q5MHtRQ= sha1:WbLC9bYllf7bRQE5K4wzp4y2Wxc= Xref: csiph.com comp.lang.c:96765 Thiago Adams writes: > On Thursday, November 17, 2016 at 3:03:40 PM UTC-2, John Bode wrote: [...] >> Not *required*, but one place where it is useful (and not immediately a >> sign of poor design or practice) is bailing out of a deeply nested loop >> or multi-step resource allocation process: >> >> for ( ... ) >> for ( ... ) >> for ( ... ) >> if ( some_error ) >> goto exit: >> >> exit: // clean up >> >> Obviously, you'll want to structure your code such that you avoid that >> situation, but sometimes it simply isn't possible (or, the level of >> effort required to do so is not worth the tradeoff). > > The other option to exit is add an external do {} while(0) and break. > > do > { > if () > { > if () > { > if () > { > break; //ok > } > } > } > } while(0); That's not helpful if you need to bail out of multiple nested loops. [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"