From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!feeder.erje.net!2.eu.feeder.erje.net!bloom-beacon.mit.edu!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!.POSTED!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: stopping a loop iteration without exiting it Date: Wed, 03 Jan 2018 18:17:58 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <81971548-23c9-4927-a6a8-6f0f1dba896b@googlegroups.com> NNTP-Posting-Host: shell02.theworld.com Mime-Version: 1.0 Content-Type: text/plain X-Trace: pcls7.std.com 1515021478 20416 192.74.137.72 (3 Jan 2018 23:17:58 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 3 Jan 2018 23:17:58 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:qnDwIJsfKtu6gay4RTA5CEo/s74= Xref: reader02.eternal-september.org comp.lang.ada:49743 Date: 2018-01-03T18:17:58-05:00 List-Id: "Randy Brukardt" writes: > A "goto" is *not* stupid in this case. I agree. There are (rare) cases in Ada when "goto" is the right solution, and nested "continue" can be one of them. I've even heard the argument that "Goto CAN always be replaced by if/while/etc" (proved by Jacopini in the 60's, IIRC), that therefore "Goto SHOULD always be replaced by if/while/etc". That "therefore" is obviously a logical fallacy. >... It isn't always sensible to > restructure a loop to avoid "continue". We looked at adding the feature > sometime back (it happens hundreds of times in the GNAT source code), but > the decision was that a goto was good enough. In fact, the goto is BETTER than the continue statement, because the place where it's jumping to is marked with a label, as in Randy's example below. With a "continue", when you see "end loop" (or "}"!) you have no clue that "something is interesting here -- somebody is jumping to this place". Jeff's suggestion (nested 'if' in the loop) is a good one when it works, but it doesn't work when the "continue" is nested within further control constructs. >...(Especially after the syntax > change allowing it directly at the end of a loop.) That is: > > loop > ... > goto Continue; > ... > <> > end loop; And Randy indents the "goto" a lot, to show that it is (perhaps) deeply nested. That's exactly when the goto makes good sense. - Bob