comp.lang.ada
 help / color / mirror / Atom feed
From: Gary Scott <Gary.L.Scott@lmtas.lmco.com>
Subject: Re: How to make like Fortran "do i = 1,20,2"
Date: 2000/07/28
Date: 2000-07-28T00:00:00+00:00	[thread overview]
Message-ID: <3981A390.A1F3D127@lmtas.lmco.com> (raw)
In-Reply-To: 7rhf9bb362.fsf@butter.albany.duck.com



Matthew J Heaney wrote:
> 
> Gary Scott <Gary.L.Scott@lmtas.lmco.com> 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<int> intList;
> ...
>    list<int>::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.)




  reply	other threads:[~2000-07-28  0:00 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-07-27  0:00 How to make like Fortran "do i = 1,20,2" Reinert Korsnes
2000-07-27  0:00 ` Ken Garlington
2000-07-27  0:00 ` des walker
2000-07-27  0:00   ` Gary Scott
2000-07-27  0:00   ` tmoran
2000-07-28  0:00     ` Reinert Korsnes
2000-07-28  0:00       ` Gautier
2000-07-29  0:00       ` tmoran
2000-07-27  0:00 ` Larry Kilgallen
2000-07-27  0:00   ` Gary Scott
2000-07-27  0:00     ` Matthew J Heaney
2000-07-28  0:00       ` Gary Scott [this message]
2000-07-28  0:00         ` mjsilva
2000-07-29  0:00         ` Ehud Lamm
2000-07-28  0:00           ` Richard Riehle
     [not found]           ` <39833637.3B83BFAC@lmtas.lmco.com>
2000-07-29  0:00             ` Gary Scott
2000-07-29  0:00           ` Robert I. Eachus
2000-07-27  0:00     ` mjsilva
2000-07-27  0:00     ` Pat Rogers
2000-07-27  0:00     ` Larry Kilgallen
2000-07-27  0:00 ` Lutz Donnerhacke
2000-07-27  0:00 ` G. de Montmollin
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox