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 05:44:29 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!server3.netnews.ja.net!south.jnrs.ja.net!server2.netnews.ja.net!CAMPUS.UniversityofEssex.com NNTP-Posting-Host: 155.245.41.148 Newsgroups: comp.lang.ada Date: Fri, 28 Jun 2002 13:29:16 +0100 Message-ID: <3d1c5614.14995249@news.essex.ac.uk> Sender: "Sangwine, Stephen J" From: sjs@essex.ac.uk (Steve Sangwine) Subject: Re: Trivial Ada question Organization: University of Essex References: X-Newsreader: Forte Free Agent 1.21/32.243 Xref: archiver1.google.com comp.lang.ada:26765 Date: 2002-06-28T13:29:16+01:00 List-Id: On Fri, 28 Jun 2002 11:54:50 +0100, Reinert Korsnes wrote: How about: declare All_OK : Boolean := True; begin for I in A'Range loop All_OK := All_OK and Some_Condition(I); exit when not All_OK; end loop; if All_OK then N := N + 1; end if; end; This has the benefit of being clear (almost self explanatory), but maybe not as concise as would be liked. Steve Sangwine >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; > 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 >>> >>>