Arrays
Introduction
An
array
is a
colleuion
of
variables
arranged
in
a way
that
allows
you to use them easily in a
computer
program.
The
most
common
way of grouping variables is in a list. which is called a one-
dimensional array.
Each
variable
in
the list is called
an
element
of
the
array.
The
length of
the
list
is
limited only
by
the
amount
of
memory
available.
By
using
the
array
capability of
TI
BASIC you can do
many
things
with a list - you
can
print
the elements forward or
backward,
rearrange
them.
add
them
together,
multiply
them.
or
select
certain
ones for processing.
In
TI
BASIC an
array
may
begin with element 0
or
element
1.
By
using the
OPTION
BASE
statement,
you control which beginning
clement
the
computer
establisl1es.
For
consistency in
describing
arrayS. we
are
assuming
that
the first
clement
in
each
array
is
element 1.
Let's
say
you
want
to use the
computer
to
take
two lists of four
numbers
and
print
all possible combinations of the
numbers
in both
lists. You might call the first
array
X
and
the
second
one
Y.
Since
X
and Y
name
a collection
of
numbers.
rather
than
a single variable.
the
computer
needs a way to refer to the individual elements in
each
array.
You
must
supply a pointer. called a subscript, to
the
particular
element in
the
array
you
want
the
computer
to use.
This
subscript
is enclosed in
parentheses
and
always immediately
follows
the
name of the array.
The
subscript
may
be explicit.
such
as X(3). which refers
to
the third clement in list
X,
or
it
may
be a
variable,
as
in X(T),
where
the value of T points to the
proper
element.
In
any
case, the subscript
is
always either a positive
integer or zero.
The
program
on
the
right pairs the
numbers
in
array
X
and
array
Y Notice
that
by using the
array
technique only a few
program
lines
are
needed
for thi:s
rdatively
complex
procedure,
Multi-Dimensional Arrays
With
TI
BASIC you
can
extend
your use of
arrays
to
include
tduuldJ
illfUJ
JJldliull,
dl
Jdllg,eu ill I
uw:;
i:lllU
COIUlllll:;.
Ci:l
11
eu
two'
dimensional arrays.
You
can
think
of
the
TIC-TAe-TOE
game
as
an
example
of a two-dimensional array,
iti
°
X
OXX
XOO
II
-1
OR
Examples:
>NEW
>100
REM
THIS
PROGRAM
PAIRS
TWO
LISTS
>110
REM
LINES
120
TO
150
ASSIGN
VALUES
TO
LIST
X
>120
FOR
T=1
TO
4
>130
READ
XCTJ
>140
NEXT
T
>150
DATA
1,3,5,7
>160
REM
LINES
170
TO
200
ASSIGN
VALUES
TO
LIST Y
>170
FOR
S=l
TO
4
>180
READ
yes)
>190
NEXT
S
>200
DATA
2,4,6,8
>210
REM
LINES
220
TO
270
PAIR
THE
LISTS
AND
P~INT
THE
COMBINATIONS
>220
FOR
T=1
TO
4
>230
FOR
S=1
TO
4
>240
PRINT
XCT);Y(S);"
".
>250
NEXT
S
>260
PRINT
>270
NEXT
T
>;'RO
E'N!)
>RUN
1 2 1 4 1 6 1 B
3 2 3 4 3 6 3 B
5 2 5 4 5 6 5 g
7 2 7 4 7 6 7 8
**
[)ONE
**
User's Reference GUlde