comp.lang.ada
 help / color / mirror / Atom feed
From: johnherro@aol.com
Subject: Re: loop step function
Date: 1997/01/27
Date: 1997-01-27T00:00:00+00:00	[thread overview]
Message-ID: <19970127125200.HAA26735@ladder01.news.aol.com> (raw)
In-Reply-To: mheaney-ya023280002501971026000001@news.ni.net


Perhaps there's also another reason that a STEP clause was deliberately
omitted from Ada.  In many languages, the index of the FOR loop has to be
a numeric (integer in most languages, but in Basic it may also be a
float).  However, in Ada the index could be any discrete type, such as an
enumeration type.  It doesn't have to be numeric.  Here's my favorite
emumeration type:

type CLA_Message_Type is (Ask_For _Help, Give_Help, Discuss_Ada,
Please_Do_My_Homework, Flame, Flame_The_Flamer);

Now in Ada you could write

for L in Ask_For_Help .. Flame loop

just as easily as you could write "for J in 1 .. 10 loop".  It would make
sense to allow a STEP 2 clause for J, because you could add 2 to J.  But
you certainly couldn't add 2 to L.  No STEP clause would make sense for L.
 For consistency, Ada doesn't allow a STEP clause for any FOR loop, even
if the index is numeric.

The reason pointed out earlier, that incorrect loop termination is a
frequent source of error, is certainly another valid reason why Ada
deliberately omitted the STEP clause.

- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor




  reply	other threads:[~1997-01-27  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 ` Geert Bosch
1997-01-25  0:00 ` Matthew Heaney
1997-01-27  0:00   ` johnherro [this message]
1997-01-27  0:00     ` Michael Feldman
1997-01-25  0:00 ` Larry Kilgallen
1997-01-29  0:00   ` Ted Dennison
1997-01-30  0:00     ` Robert Dewar
replies disabled

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