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/28 Message-ID: <3981A390.A1F3D127@lmtas.lmco.com>#1/1 X-Deja-AN: 651863133 Content-Transfer-Encoding: 7bit References: <8lpcbe$40n$1@news.uit.no> <39805669.3E7CF6CF@lmtas.lmco.com> <7rhf9bb362.fsf@butter.albany.duck.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: LMTAS Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-07-28T00:00:00+00:00 List-Id: Matthew J Heaney wrote: > > Gary Scott writes: > > > Hmmm, these and similar examples posted do not make Ada look very > > elegant...it makes a very simple concept seem somewhat convoluted. > > This "very simple concept" is a major source of bugs -- that's why it's > not in the language. "Studies" of language usage and error inducing constructs can be made to support virtually any preconceived notion. I'm more interested in producing the code that solves a particular problem in the easiest to understand and straightforward form rather than in the most elegant in terms of abstraction. Of course it is very common to use steps in languages with somewhat limited alternative constructs in certain circumstances when the problem might be solved in another way more clearly and/or elegantly. Fortran 95 supports all of the alternative methods presented so far in addition to the single DO-STEP construct. > > If you want to increment by 2 through the loop, it's simple enough: > > declare > I : Positive := A'First; > begin > while I <= A'Last loop > ... A(I) ... > I := I + 2; > end loop; > end; > > QED > > If you want to do odd-ball things, then sometimes that requires extra > work. The common things (like incrementing the loop index by 1) are > easy to do. > > I can't even remember the last time I had to iterate over an array by an > increment other than 1. > > Consider this analogy. Suppose you want to iterate over a linked list: > > list intList; > ... > list::iterator iter = intList.begin(); > > In the normal case, when you increment by 1, it's simple: > > while (iter != intList.end()) > { > ... > iter++; > } > > Asking how to iterate in increments of 2 is like asking, How do I visit > every other list element? That's an odd-ball thing to do, so you have > to do extra work. (Try it and you'll see.)