DIM
Subscripting
An
Array
Anytime you
want
to
reference
an
array
ill
yUUl
~l
U~l
cUll.
you
rnust
be specific
about
which
element
in the
array
you
want
the
computer
to use. To do this. you point to the
element
with a subscript.
Subscripts
are
enclosed in
parentheses
immediately fulluwiug the
name
of the
array.
A
subscript
can
be
any
valid
numeric
expression
which
evaluates
to a non-negative result.
This
result
will
be
rounded
to the
nearest
integer, if necessary.
The
number
of elements reserved for
an
array
determines
the
maximum
value
of
each
subscript
for
that
arr<lY
Tf
y01l
;.1[1'
llsing
an
array
not
defined
in
a
DIMension
statement.
the
maximum
value of
each
subscript
is
10.
The
minimum value is zero, unless
an
OPTION
BASE
statement
sets
the
minimum
subscript
value
at
1.
Thus
an
array
defined as DIM A(6) actually
has
seven
accessible elements
in
TI
BASIC. unless the zero
subscript
is
eliminated
by
the
OPTION
BASE
1
statement.
The
example
on
the
right
assumes
that
the
array
begins with
element 1
(OPTION
BASE
1
on
line 120):
• line
130
-
This
line defines T as a one-dimensional
array
with 25 elements.
• Ime
16U -
The
numeric
variable I
here
subscripts
T.
Whatever
value I contains
at
this time will be used to point
to
an
element
of
T.
If
I
=3,
the third
element
of T will be
added.
-line
200
-
The
subscript
14
tells the
computer
to print the
fourteenth
element
of
T.
• line
220
-
The
computer
will
evaluate
the
numeric
expression
N
+2,
UN
=15
at
this time, the
seventeenth
element
of
T
will
be
printed.
If
you
access
an
array
with a
subscript
greater
than
the
maximum
number
of
elements
defined for
that
array.
or
if
your
subscript
has
a
zero value
and
you used
an
OPTION
BASE
1
statement,
a "BAD
SUBSCRIPT"
message will
print
and
the
program
will end.
User's
Reference
Guide
Examples:
>NEW
>100
RE~
DE~O
OF
DI~
AND
SUBSCRIPTS
>110
S=100
>120
OPTION
BASE
>130
[)l~
T(25)
>140
FOR
1=1
TO
25
>150
READ
T(I)
>160 A=S+T(1)
>170 PRINT
A;
>180 NEH I
>190
PRINT::
>200 PRINT
T(14)
>210
INPUT
"ENTER
A
NUMBER
BE
TWEEN
1
AND
23:":N
>220 PRINT T(N+2)
>230
DATA
12,13,43,45,65,76,7
8,98,56,34,23,21,100,333,222
,111,444,666,543,234,89,765,
90,101,345
>240
END
>RUN
112 113 143 145 165
176 178
198 156 134
123
121 200 443 322
211
544 766 643 334
189
865 190
201
445
333
ENTER
A
NUMBER
BETWEEN
1
AND
23:
14
111
,.,.
DONE
**
II-Ill