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=-0.1 required=5.0 tests=AXB_XMAILER_MIMEOLE_OL_024C2, BAYES_00,MAILING_LIST_MULTI,REPLYTO_WITHOUT_TO_CC autolearn=no 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:09:03 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!isdnet!enst!enst.fr!not-for-mail From: "David C. Hoos, Sr." Newsgroups: comp.lang.ada Subject: Re: Trivial Ada question Date: Fri, 28 Jun 2002 05:10:40 -0500 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: References: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: avanie.enst.fr 1025258942 19687 137.194.161.2 (28 Jun 2002 10:09:02 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Fri, 28 Jun 2002 10:09:02 +0000 (UTC) Return-Path: X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Original-Cc: reinert.korsnes@chello.no Xref: archiver1.google.com comp.lang.ada:26760 Date: 2002-06-28T05:10:40-05:00 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 > >