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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f6a85e71d2c330ab X-Google-Attributes: gid103376,public From: "DuckE" Subject: Re: checking a loop execution Date: 2000/04/19 Message-ID: <38fe720b.0@news.pacifier.com>#1/1 X-Deja-AN: 613414448 References: <8dl76u$etf$1@nnrp1.deja.com> X-Trace: 19 Apr 2000 19:57:15 PST, 198.145.227.45 X-MSMail-Priority: Normal X-Priority: 3 Newsgroups: comp.lang.ada X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 Date: 2000-04-19T00:00:00+00:00 List-Id: First: Your example will result in an undefined value for ivar if is never met. Second: I sometimes use the construct: procedure loop_test is begin for i in 1 .. 10 loop if then put( i, 2 ); return; end if; end loop; put( defaultValue, 2 ); -- default value when condition is never met end loop_test; I don't know if it's more or less efficient, but it does eliminate the extra variable. BTW: I usually avoid having more than one exit point from a procedure, but in a routine this small I think it actually reads better. SteveD wrote in message news:8dl76u$etf$1@nnrp1.deja.com... > Is there a way to check if a loop has been exited before completion or > if all iterations have been performed? > In fortran the loop index is increased one last time, at the end of > the loop, but in Ada that trick cannot be exploited; the index is not > even defined outside the loop. > I could add a control variable (ivar, in my example) to take care of the > iteration number when exiting, but that would decrease the peformance > of my algorithm > > Example > > procedure loop_test is > > ivar : integer; > > begin > for i in 1 .. 10 loop > if then > ivar := i; > exit ; > end if ; > end loop; > put(ivar,2); > end loop_test; > > > > thank you for your suggestions > > Pol > > > Sent via Deja.com http://www.deja.com/ > Before you buy.