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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,14f7200925acb579 X-Google-Attributes: gid103376,public From: tmoran@bix.com Subject: Re: No Go To's Forever! Date: 2000/03/24 Message-ID: #1/1 X-Deja-AN: 601530965 References: <8baqlu$3qp$1@nnrp1.deja.com> X-Complaints-To: abuse@pacbell.net X-Trace: news.pacbell.net 953856117 206.170.2.248 (Thu, 23 Mar 2000 16:01:57 PST) Organization: SBC Internet Services NNTP-Posting-Date: Thu, 23 Mar 2000 16:01:57 PST Newsgroups: comp.lang.ada Date: 2000-03-24T00:00:00+00:00 List-Id: >Of course you could argue that it is easier to find your refined >superior form from my syntactic expression with nested loops >than from the original with a goto, and that would be an >interesting argument to make. For example: > following sorting algorithm: > > <> > for J in 1 .. N - 1 loop > if D (J) < D (J + 1) then > Swap (D (J), D (J + 1)); > goto Do_It_Again; > end if; > end loop; re-written with While instead of goto is J := D'first; while J < D'last loop if D (J) >= D (J + 1) then -- sorted so far J := J+1; -- continue else Swap (D (J), D (J + 1)); -- out of order, move item J := D'first; -- and start over end if; end loop; which practically makes you trip over an obvious improvement in the algorithm to J := D'first; while J < D'last loop if D (J) >= D (J + 1) then -- sorted so far J := J+1; -- continue else Swap (D (J), D (J + 1)); -- out of order, move item if J > D'first then -- and start checking at J := J-1; -- the first changed spot end if; end if; end loop;