comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@ni.net (Matthew Heaney)
Subject: Re: loop step function
Date: 1997/01/25
Date: 1997-01-25T00:00:00+00:00	[thread overview]
Message-ID: <mheaney-ya023280002501971026000001@news.ni.net> (raw)
In-Reply-To: 32E93C0B.36A@cloud9.net


In article <32E93C0B.36A@cloud9.net>, pvanbell@cloud9.net wrote:

>The FOR loop does
>not have a "STEP" option. In order to perform a loop function using a
>variable's range of values but in steps greater than the variable
>kernel, you seem to have to use a WHILE loop with the variable
>incremented within the loop by the step size. Is there a more elegant
>way of doing this?

This is a *deliberate* omission in the langauge.

Here is a clue about why Ada doesn't have a step option:

   Programming is a Human Activity

Ada was engineered for use by humans, who tend to make mistakes.  It was
designed to omit features in other languages that tended to be error prone.

   Ada was designed for use by human programmers

Empirical studies had been done to determine what mistakes were common
among human programmers, and one of the mistakes that programmers always
make is getting loop termination correct.

Figuring out what the last value is during iteration is often difficult and
error prone.  Ada solves the problem by only allowing a step size of one,
thus removing the difficulty and removing the source of error.

Just think of Ada's for loop as meaning "this states directly how many
times I iterate."  And that quantity isn't necessarily the same as the
number I use in the algorithm.

So Ada's for loop is the no-brainer way to iterate across the values of a
discrete type.

As Larry pointed out in another post, if you need some other value (that
you would use a for-step in another language), then use a local declare
block to calculate the value.

I've been programming in Ada for 10 years, and I can't remember even one
time needing a value other than one as my step value.

If I were going to design a glove for use by humans, then I would design it
to fit the shape of the human hand.  If I were going to design a
programming language for use by humans, then I would design it to fit the
cognitive capacities of the human brain.

That language is Ada.

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




  parent reply	other threads:[~1997-01-25  0:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-01-24  0:00 loop step function Paul Van Bellinghen
1997-01-25  0:00 ` Larry Kilgallen
1997-01-29  0:00   ` Ted Dennison
1997-01-30  0:00     ` Robert Dewar
1997-01-25  0:00 ` Matthew Heaney [this message]
1997-01-27  0:00   ` johnherro
1997-01-27  0:00     ` Michael Feldman
1997-01-25  0:00 ` Geert Bosch
replies disabled

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