,40
If
you
use an index
that
refers
to
an
element
that
does
not
exist in
the
array,
the
instruction
cannot
be
executed
and
INDEX ERROR results:
A
11
12
13
1~
15
16
17
A[8]
INDEX
ERROR
ACBJ
A
You
cannot
index or
do
anything else with an array until
after
the
array has been
specified. For example, suppose
that
no value has been assigned
to
the
name Z;
then
an
attempt
to
store
values
in
certain elements within Z would result
in
an
error, since those elements
do
not
exist:
Z[3
I.J·]~":I.B
'+6
VALUE
ErJ.rJ.D'~
Z
I::
3
I~.
::I
~..
:1.
B
I.).
b
/'0.
Indices (whatever
is
inside
the
brackets) can be expressions, provided
that
when
those
expressions are finally evaluated,
the
results are values
that
represent valid
indices for
the
array:
B
ABCDEFGH
I
,..II{
I...MNO
P(~
RSTUVWXYZ
X~-1
2 3
4·
~:=;
B[Xx2]
BDFH,J
X
1 2 3
~
5
B[1+Xx:~J
The
array from which elements are selected
does
not
have
to
be a variable.
For
example, a vector can be indexed as follows:
2 3 5 7 9 11
13 15
17
19[7
2
~
2]
13
3 7 3
'ABCDEFGHIJKLMNOPQRSTUVWXYZ
'[12
15
15
11
27
16
1]
l..OOI(
PA
•
{i
BCD E F 0 H I
,"/1<
I...
r"'1
N
[I
P
(-).
F-~
STU \/
t·
.
.!
X '{
:?:
'I::
:::.:~
1+
(,1+
1
~.:.:.i
ll.j·
"':,":.1
......
I
:I.
:::~;
:I.
J D
::?
~.:.:.i
J
nDN
~~
r'i(.:,R\'
-~------
______
~
~
The
shape
of
the
result
is
the
same as
the
index.
/ '}
"
....
,