Sharp OZ-707 Operation Manual - Page 24

An n-dimensional array is declared by the statement - 320

Page 24 highlights

The first statement creates an array X with 6 storage locations. The second statement creates an array AA with 25 locations. The third statement creates an array with one location and is actually illogical since (for numbers at least) it is the same as declaring a single-value numeric variable. It is important to know that an array-variable X and a variable X are separate and distinct to the Card. The former denotes a series of numeric storage locations, and the latter denotes a single and different location. Now that you know how to create arrays, you might be wondering how we refer to each storage location. Since the entire group has only one name, the way in which we refer to a single location (called an "element") is to follow the group name with a number in parentheses. This number is called a "subscript". For example, to store the number 8 in the fifth element of our array X (declared previously) we would write: X(4) = 8 If the use of 4 is puzzling, remember that the numbering of elements begins at zero and continues through to the number of elements declared in the DIM statement. The real power of arrays lies in the ability to use an expression or a variable name as a subscript. An n-dimensional array is declared by the statement: DIM array-variable-name (size 1, size 2, ..., size n) where: size n specifies the number of elements in the nth dimension of the array. Note that when you specify the number of elements, you get one more element than indicated by the specification. The following diagram illustrates the storage locations that result from the declaration DIM T(2, 3) and the subscripts (now composed of two numbers) that pertain to each location: 36 row 0 row 1 row 2 column 0 T (0,0) T (1, 0) T (2, 0) column 1 T (0, 1) T (1, 1) T (2, 1) column 2 T (0, 2) T (1, 2) T (2, 2) column 3 T (0, 3) T (1 , 3) T (2, 3) Note: Two-dimensional arrays can rapidly use up storage space. For example, an array with 25 rows and 35 columns uses 875 storage locations! An n-dimensional array has n indices into the array. For example, DIM Z$(3,3,3,4) generates a 4-dimensional array with 320 elements. The following table shows the number of bytes used to define each variable and the number used by each program statement. Variable type Single-precision numeric variable Double-precision numeric variable String (array) variable Number of bytes used Variable name Data (Length of variable name + 4) bytes 7 bytes (Length of variable name + 4) bytes 12 bytes (Length of variable name + 8) bytes The number of stored string (array) data (bytes) Element Number of bytes used Line number 3 bytes Statement & function 2 bytes I ENTER I 1 byte Double-Precision Variables Existing single-precision variables can be converted to double-precision variables by appending a sharp mark (#). For example: A#, AB#, X#(10), Y#(2,3) and X1#(5,6). 37

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128

The first statement creates
an
array X with 6 storage locations. The
second statement creates
an
array AA with 25 locations. The third
statement creates an array with one location and
is
actually illogical
since (for numbers at least) it is the same as declaring a single-value
numeric variable.
It is important to know that
an
array-variable X and a variable X
are
separate and distinct to the Card. The former denotes a series of
numeric storage locations,
and
the latter denotes a single and different
location.
Now
that you know how to create arrays, you might be wondering how
we refer to each storage location. Since the entire group has only one
name, the way in which we refer to a single location (called
an
"element")
is
to follow the group name with a number in parentheses.
This number
is
called a "subscript". For example, to store the number
8
in the fifth element of our array X (declared previously) we would write:
X(4)
=
8
If the use of 4
is
puzzling, remember that the numbering of elements
begins at zero and continues through to the number of elements
declared
in
the DIM statement.
The real power of arrays lies
in
the ability to use
an
expression or a
variable name
as
a subscript.
An n-dimensional array is declared by the statement:
DIM
array-variable-name (size
1,
size
2,
... , size
n)
where:
size n
specifies the number of elements
in
the
nth
dimension of
the array. Note that when you specify the number of elements,
you get one more element than indicated by the specification.
The following diagram illustrates the storage locations that result from
the declaration DIM T(2,
3)
and the subscripts (now composed of two
numbers) that pertain to each location:
36
Note:
row 0
row 1
row 2
column 0
T
(0,0)
T
(1,
0)
T
(2,
0)
column 1
T
(0,
1)
T
(1,
1)
T
(2,
1)
column 2
column 3
T
(0,
2)
T
(0
,
3)
T
(1,
2)
T
(1
,
3)
T
(2,
2)
T
(2,
3)
Two-dimensional arrays can rapidly use up storage space. For
example,
an
array with 25 rows and 35 columns uses 875 storage
locations!
An
n-dimensional array has n indices into the array.
For example,
DIM
Z$(3,3,3,
4)
generates a 4-dimensional array with
320 elements.
The following table shows the number of bytes used to define each
variable and the number used by each program statement.
Variable
type
Number of bytes used
Variable name
Data
Single-precision nume
ri
c
(Length of variable
7 bytes
variable
name
+
4) bytes
Double-precision numeric
(Length of variable
12 bytes
variable
name
+
4) bytes
String (array) variable
(Length of variable
The number of
name
+
8)
bytes
stored string
(array) data (bytes)
Element
Line number
Statement
&
I
ENTER
I
function
Number of
3 bytes
2 bytes
1 byte
bytes used
Double-Precision Variables
Existing single-precision variables can be converted to double-precision
variables by appending a sharp mark (#). For example:
A#, AB#, X#(10), Y#(2,3) and X1#(5,6).
37