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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,459feef56669b92d X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-03 06:02:11 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!feed.news.qwest.net!namche.sun.com!news1brm.central.sun.com!new-usenet.uk.sun.com!not-for-mail From: Ole-Hjalmar Kristensen Newsgroups: comp.lang.ada Subject: Re: "continue/next" for "loop" Date: 03 Nov 2003 14:54:17 +0100 Organization: Sun Microsystems Message-ID: References: NNTP-Posting-Host: khepri06.norway.sun.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: new-usenet.uk.sun.com 1067867658 22404 129.159.112.195 (3 Nov 2003 13:54:18 GMT) X-Complaints-To: usenet@new-usenet.uk.sun.com NNTP-Posting-Date: 3 Nov 2003 13:54:18 GMT User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:1976 Date: 2003-11-03T13:54:18+00:00 List-Id: >>>>> "LD" == Lutz Donnerhacke writes: LD> * amado.alves wrote: >>> No. I don't know how to invert a complex loop. >> >> What on Earth are you talking about? The two constructs >> >> (1) if I mod J = 0 then >> goto next; >> end if; >> Put (I'Img); >> <> null; >> >> (2) if I mod J /= 0 then >> Put (I'Img); >> end if; >> >> are clearly equivalent! LD> But both are the result of an oversimplification! LD> outer: loop LD> inner: loop LD> Complex_Actions_1; LD> if First_Condition then LD> Some_Justify_Actions; LD> goto next_outer; LD> end if; LD> Complex_Actions_2; LD> if Second_Condition then LD> Some_Other_Justify_Actions; LD> goto next_outer; LD> end if; LD> Complex_Actions_3; LD> end loop inner; LD> Complex_End_Statments; LD> exit outer when Other_Condition; LD> More_Statments; LD> <> null; LD> end loop outer; LD> I'd like to find a more amazing version of this braindead goto. LD> Please do not assume, that I'm too stupid to invert a condition in a LD> simplified example. IT'S NOT HOMEWORK! It seems you are looking for a multi-level "continue" statement :-) You need to somehow store the results of your tests if you want to avoid the goto, because this information is used outside the scope of the inner loop. A boolean should suffice, but is the code any more readable? outer: loop declare execute_outer_statements : boolean := false; begin inner: loop Complex_Actions_1; if First_Condition then Some_Justify_Actions; else Complex_Actions_2; if Second_Condition then Some_Other_Justify_Actions; else Complex_Actions_3; execute_statements := true; end if; end if; end loop inner; if execute_outer_statements then Complex_End_Statments; exit outer when Other_Condition; More_Statments; end if; end; end loop outer; You could of course make your inner loop an inline procedure returning a boolean to separate the logic of the inner and outer loops more clearly: outer: loop declare procedure inner_loop(doit : out boolean) is begin Complex_Actions_1; if First_Condition then Some_Justify_Actions; doit := false; else Complex_Actions_2; if Second_Condition then Some_Other_Justify_Actions; doit := false; else Complex_Actions_3; doit := true; end if; end if; end inner_loop; pragma inline(inner_loop); execute_outer_statements : boolean; begin inner_loop(execute_outer_statements); if execute_outer_statements then Complex_End_Statments; exit outer when Other_Condition; More_Statments; end if; end; end loop outer; After looking at these alternatives, I would probably stick with the goto. -- Strange attractors stole my wife