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.2 required=5.0 tests=BAYES_00,FROM_WORDY, 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: "Ken Garlington" Subject: Re: How to make like Fortran "do i = 1,20,2" Date: 2000/07/27 Message-ID: #1/1 X-Deja-AN: 651591207 References: <8lpcbe$40n$1@news.uit.no> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Complaints-To: abuse@flash.net X-Trace: news.flash.net 964736495 216.215.69.205 (Thu, 27 Jul 2000 17:21:35 CDT) Organization: FlashNet Communications, http://www.flash.net X-MSMail-Priority: Normal NNTP-Posting-Date: Thu, 27 Jul 2000 17:21:35 CDT Newsgroups: comp.lang.ada Date: 2000-07-27T00:00:00+00:00 List-Id: "Reinert Korsnes" wrote in message news:8lpcbe$40n$1@news.uit.no... > > 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; > > Yes, I can use: > > I := A'first; > while I <= A'Last loop; > something.. > I := I + 2; > end loop; > > But this does not look so elegant.... Just off the top of my head: for I in Beginning_Selection .. Final_Selection loop something involving A(Selected_By(I)); end loop; where the functions come from a generic with a Step constant and an array index type as parameters, with functions sketched as Beginning_Selection: Type'First; Final_Selection: Type'First + (Type'Length/Step) - 1 -- depends upon what you want to do with odd-valued arrays, etc. Selected_By(I): I * Step;