Just to throw in a twist....
Take a look at DSPDTAARA output. Offset 0 = Position (or Index) 1. It
combines the best of both worlds.
shc@xxxxxxxxxxxxxxxxx 02/02/2009 1:14:53 PM >>>
On 02/02/2009, at 11:41 PM, Vern Hamberg wrote:
I'm trying to figure this out, too. This is how a FOR loop is supposed
to operate - the test exceeds the limit.
That's correct.
The original question was why we start with 1
No, the original was a comment on observed behaviour i.e., that the
index variable must be capable of holding a value at least 1 greater
than the loop limit. That lead on to a pointless discussion of "Why
is it so?" which in turn lead to unfounded supposition that the
starting value may have some bearing on the terminal value.
- example given was a FOR
loop - but I suspect the question was really about array bases -
zero-based for C/C++, say.
No, more that loops are frequently used to iterate over arrays
therefore the starting value must have some relationship to the index
of an array element. Some languages let you choose the boundary
range--negative array indices anyone? In non-C-derived languages
arrays are generally 1-based, In C-derived languages arrays are
generally 0-based. However, in all programming languages (at least
that I can think of), on for-loop termination, the index of the loop
is always 1 greater than the terminal value--regardless of the
starting value.
I and others have offered some speculation on
that, and have moved tangentially into errors when the loop counter
may
exceed the limits of the data type used for that variable. So I'm
flatly
getting a little lost!! See my last post in response to this.
No, that's where we started so if we're back to range errors on the
loop index then we've come full-circle. So what are we discussing again?
Regards,
Simon Coulter.
--------------------------------------------------------------------
FlyByNight Software OS/400, i5/OS Technical Specialists
http://www.flybynight.com.au/
Phone: +61 2 6657 8251 Mobile: +61 0411 091 400 /"\
Fax: +61 2 6657 8251 \ /
X
ASCII Ribbon campaign against HTML E-Mail / \
--------------------------------------------------------------------
As an Amazon Associate we earn from qualifying purchases.