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,7596cfba54ad3207 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-06-28 03:57:38 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!128.39.3.168!uninett.no!not-for-mail From: Reinert Korsnes Newsgroups: comp.lang.ada Subject: Re: Trivial Ada question Date: Fri, 28 Jun 2002 12:57:31 +0200 Organization: UNINETT Message-ID: References: NNTP-Posting-Host: sthrkou.ffi.no Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: dolly.uninett.no 1025262027 26217 193.156.99.159 (28 Jun 2002 11:00:27 GMT) X-Complaints-To: news-abuse@uninett.no NNTP-Posting-Date: Fri, 28 Jun 2002 11:00:27 +0000 (UTC) User-Agent: KNode/0.7.1 Xref: archiver1.google.com comp.lang.ada:26762 Date: 2002-06-28T12:57:31+02:00 List-Id: Correction below. It always happens :-) reinert Reinert Korsnes wrote: > Yes, maybe the simplest possible. > The example below is also somehow simple, > but I hoped for some "exit name" solution > which I have not yet noticed :-) > > reinert > > All_OK := 1; > for I in A'Range loop > if not some condition (I) then > All_OK := 1; obs, I mean All_OK := 0; > exit; > end if; > end loop; > N := N + All_OK; > > > David C. Hoos, Sr. wrote: > >> How about >> >> All_OK : Boolean; >> . >> . >> . >> All_OK := True; >> for I in A'Range loop >> if not some condition (I) then >> All_OK := False; >> exit; >> end if; >> end loop; >> if ALL_OK then >> N := N + 1; >> end if; >> >> ----- Original Message ----- >> From: "Reinert Korsnes" >> Newsgroups: comp.lang.ada >> To: >> Sent: June 28, 2002 4:07 AM >> Subject: Trivial Ada question >> >> >>> Hi, >>> >>> I would like to ask about a program construct: >>> >>> I want to test if some condition holds for all values >>> of I in A'range and in this case the variable >>> N should be incremented by one ( N := N + 1; ). >>> How can I do this most elegant and effective with Ada95 >>> (without "goto") ? >>> Assume I do not want to make a separate subroutine for this. >>> >>> This example is simple but not computationally optimal (two tests): >>> >>> for I in A'range loop >>> exit when "not some condition(I); >>> if I = A'last then >>> -- Everything OK to the end: >>> N := N + 1; >>> end if; >>> end loop; >>> >>> This example is ugly but more computationally optimal (one test): >>> >>> for I in A'range loop >>> if "not some condition(i)" then >>> N := N - 1; >>> exit; >>> end if; >>> end loop; >>> N := N + 1; >>> >>> Tricks by "named loops" also seem ugly. >>> >>> reinert >>> >>> _______________________________________________ >>> comp.lang.ada mailing list >>> comp.lang.ada@ada.eu.org >>> http://ada.eu.org/mailman/listinfo/comp.lang.ada >>> >>>