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-Thread: a07f3367d7,da5197b9dca0ed40 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nntp.club.cc.cmu.edu!feeder.erje.net!eternal-september.org!.POSTED!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Processing array subsections, a newbie question. Date: Sat, 12 Jun 2010 22:54:38 +0200 Organization: A noiseless patient Spider Message-ID: <8739wsottd.fsf@ludovic-brenta.org> References: <4c13db30$0$2391$4d3efbfe@news.sover.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Sat, 12 Jun 2010 20:54:38 +0000 (UTC) Injection-Info: mx01.eternal-september.org; posting-host="5AIA3OkoYa1sp4ScMfQtFw"; logging-data="12787"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+4/J37uuIKsoCrTc1nj7cQ" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:tD8X/QcZkvLDjs2QiXkKYnQr+KE= sha1:vCzr5SdPwEnSKO/mf09wws1x720= Xref: g2news1.google.com comp.lang.ada:11667 Date: 2010-06-12T22:54:38+02:00 List-Id: "Peter C. Chapin" writes: > Ok : Boolean := True; > Index_Fst : Natural := Buffer'First; > Index_Lst : Natural; > ... > > while Ok and Index_Fst <= Buffer'Last loop > Do_Something(Buffer, Index_Fst, Index_Lst, Ok); > Index_Fst := Index_Lst + 1; > end loop; > > The problem with this code is that the assignment to Index_Fst inside the loop > might raise Constraint_Error if Index_Lst = Buffer'Last after Do_Something > finishes. I can work around this problem but my solutions tend to be rather > ungainly looking. Surely there must be an easy way to handle this. How about: Ok : Boolean := True; Index_Fst : Natural := Buffer'First; Index_Lst : Natural; ... loop Do_Something(Buffer, Index_Fst, Index_Lst, Ok); exit when not Ok; exit when Index_Fst = Buffer'Last; Index_Fst := Index_Lst + 1; end loop; -- Ludovic Brenta;