aA zero index is perfectly valid if you think of the index as actually being an offsetoffset from the base address of an array. That's the norm in fact, though it varies from dialect to dialect. With the old Jovial language, [0][0]
actually contained the maximum size of the array. so it started with ]1][1]
.
With some Basic implementations, you can arbitrarily elect to have either 00
or 11
as the first index. And at least one Basic allows you to designate arrays to index fron [n][n]
to [m][m]
. where nn
and mm
can have any integer value, even negative, as long as nn
is less than or equal to mm
. The value nn
them becomes subtracted from the [index][index]
entered, as index-n = 0index-n = 0
if index corresponds to nn
.
But you can do the same thing and more in your own code. You can even reverse the order of an array this way:
dim array(0, abs(m-n)); step=sign(m-n); if n > m then base=m else base=n; fi
dim array(0, abs(m-n));
step=sign(m-n);
if n > m then
base=m
else
base=n;
fi
This code example is actually only partly of one language. I just wanted it to be more readable. The step variable is used to control the apparent direction you are moving in whether positive or negative, and is used to calculate the effective index when going into or coming out of the array, which is actually always positive from [0][0]
.