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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,da5197b9dca0ed40 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Path: g2news2.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!usenet-fr.net!gegeweb.org!aioe.org!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Re: Processing array subsections, a newbie question. Date: Sat, 12 Jun 2010 21:38:50 +0200 Organization: Ada At Home Message-ID: References: <4c13db30$0$2391$4d3efbfe@news.sover.net> NNTP-Posting-Host: qFSKAKVBnqJLnfQ4StpZkg.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 User-Agent: Opera Mail/10.53 (Win32) Xref: g2news2.google.com comp.lang.ada:12636 Date: 2010-06-12T21:38:50+02:00 List-Id: Le Sat, 12 Jun 2010 21:11:33 +0200, Peter C. Chapin = a =C3=A9crit: > Ok : Boolean :=3D True; > Index_Fst : Natural :=3D Buffer'First; > Index_Lst : Natural; > ... > > while Ok and Index_Fst <=3D Buffer'Last loop > Do_Something(Buffer, Index_Fst, Index_Lst, Ok); > Index_Fst :=3D 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 =3D Buffer'Last after = > Do_Something I know this, this is a very common problem too me : I simply use an =E2=80= =9Cexit = when not Condition=E2=80=9D before the increment. This requires a little= redesign, = like wrapping the look in a =E2=80=9Cif Condition then=E2=80=9D. Sometime, to have something clean from the logical point of view, you mu= st = have something which is =E2=80=9Cless=E2=80=9D visually clean... or I wo= uld better say, = less short and more explicitly handles some cases which are merged = otherwise. Do you think this idea is good enough ? Does it match your requirements = ? -- = There is even better than a pragma Assert: a SPARK --# check. --# check C and WhoKnowWhat and YouKnowWho; --# assert Ada; -- i.e. forget about previous premises which leads to conclusion -- and start with new conclusion as premise.