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,e511f3ccb3da24af X-Google-Attributes: gid103376,public From: Kilgallen@eisner.decus.org.nospam (Larry Kilgallen) Subject: Re: How to make like Fortran "do i = 1,20,2" Date: 2000/07/27 Message-ID: #1/1 X-Deja-AN: 651399330 References: <8lpcbe$40n$1@news.uit.no> X-Complaints-To: abuse@verio.net X-Trace: iad-read.news.verio.net 964704702 216.44.122.34 (Thu, 27 Jul 2000 13:31:42 GMT) Organization: LJK Software NNTP-Posting-Date: Thu, 27 Jul 2000 13:31:42 GMT Newsgroups: comp.lang.ada Date: 2000-07-27T00:00:00+00:00 List-Id: In article <8lpcbe$40n$1@news.uit.no>, reinert@ola.npolar.no (Reinert Korsnes) writes: > > Hi, > > How can one in Ada elegantly make a loop through each 2 element of an array ? > I am looking for something like: "do i = 1,20,2" in Fortran, or > > for I in A'range ("step 2") loop > something... > end loop; =========== for I in A'range loop if (I - A'first) mod 2 = 0 then null; end if; end loop; But of course that does nothing to ensure that A'length is an even number. =========== for I2 in A'first/2 .. A'last/2 loop declare I : INTEGER := I2*2; begin null; end; end loop; That approach will have problems if either A'length is an odd number or if either limit of A'range is an odd number. =========== But what does Fortran do in those negative and odd number cases ?