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!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: stopping a loop iteration without exiting it Date: Sun, 07 Jan 2018 21:04:55 +0000 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="b831e4f614b7c0c82606667c2a1d06f7"; logging-data="1792"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/fxPZtfUS10ei0nSFzQT56oGNhwoB/KzE=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (darwin) Cancel-Lock: sha1:VtEvHf6gtvOH+aKzBi09NjqKLl0= sha1:e0i/AZkdnNpmYiHcAHc6IKimFhk= Xref: reader02.eternal-september.org comp.lang.ada:49805 Date: 2018-01-07T21:04:55+00:00 List-Id: Micah Waddoups writes: > On Wednesday, January 3, 2018 at 9:54:36 AM UTC-7, Mehdi Saada wrote: >> Is there a way to tell to ignore the remaining of a loop ? Like an >> exit statement, but instead of quiting the loop, it would go to the >> next iteration. >> Can we do this except with a recursive structure ? > > Of all the things I've read in this post, I think the closest thing to > the ideals and standards of Ada is the `goto My_Loop` idea. Making > any named structure flow control accessible with the goto statement, > only specifying the next loop of such, and exiting any inner loops in > the process reduces code written in some cases and more importantly, > it is very clear where the decision to exit/continue-next is made and > exactly which loop is being jumped to the next iteration. This > short-circuit behavior is similar to the `and then` and `or else` > convention used in Boolean condition testing. It seems to me that some sensible naming conventions could do the job quite well without changing the language. Foo : for J in 1 .. 10 loop if J = 5 or J = 6 then goto Continue_Foo; end if; K := K + J; <> end loop Foo; (I wanted to write <> but no) NB! I would never use a label in so small a context as this! Imagine lots of checks and lots of code to skip. Or perhaps <>, depending on how much one likes the C 'continue'.