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: Gary Scott Subject: Re: How to make like Fortran "do i = 1,20,2" Date: 2000/07/27 Message-ID: <39805669.3E7CF6CF@lmtas.lmco.com>#1/1 X-Deja-AN: 651511514 Content-Transfer-Encoding: 7bit References: <8lpcbe$40n$1@news.uit.no> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: LMTAS Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-07-27T00:00:00+00:00 List-Id: Hmmm, these and similar examples posted do not make Ada look very elegant...it makes a very simple concept seem somewhat convoluted. Larry Kilgallen wrote: > > 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 ?