Commodore 16 User Manual
Download Operation & user’s manual of Commodore 16 Desktop for Free or View it Online on All-Guides.com.
EXAMPLE:
DATA 100,
200, FRED, "WILMA",
, 3. 14. ABC123
DEF
FN
DEF FN name (variable) -
expression
This command
allows
you lo define
a complex calculation
as a
lunclion
In the
case of a
long
formula
thai is used several
times within
a
program,
this can save
a lot ol
space.
The name
you give
the
numeric
function begins
with the letters
FN,
followed
by
any lega'
numeric
variable name. First
you must
define the
function
by using the
statement
DEF
followed
by the name
you've given
the function
Following trie
name Is
a set ol parentheses
(J
with a
numeric
variable (in this
case.
X)
enclosed.
Then
you
have
an
equal
sign,
followed
by the formula
you want
to
define.
You can
"call" the
formula,
substituting
any number for
X. using
the format shown in line
20
of the
example below:
EXAMPLE
10DEFFNA(X)=12'(34.75-XA3)+X
20 PRINT
FNA(7)
The number 7
is inserted
each
piace
X
is located
In
the formula
given
m the DEF
statement.
NOTE:
DEF FN can only
be used wnh standard
numeric functions,
not integer or string
functions.
i
(
(
i
(
i
i
!
I
114
I I
I
I
I !
I I
I
I
(
1
I
(
I
I
I
I
I . I
I !
( I
I I
I I
(
I
DIM
DIM variable (subscripts)
[
variable*subset ipts))
,
Betore
you can use an array of variables, the program must ftrsl
execute a DIM statement to
establish the DIMensions of that array
(unless there are 1
1
or fewer elements in the array). The statement DtM
is followed
by
the name of trie array, whicn, may
be
any legal variable
name.
Then,
enclosed In parentheses,
you put the
number
(or
numeric
variable) of elements In each dimension An array with more lhan one
dimension
is called a malnx You may use any
number of dimensions,
but keep
tn mind that
the
whole list of variables
you
are creating takes
up space In memory, and it Is easy lo run out of memory if you gel
carried away. To figure the number of variables created with
each
DIM.
multiply
Ihe
total number of e'ements In
each
dimension of the array
(Each array
starts
with element
0.)
NOTE: Integer (single-digit) arrays take
up
2/5ths of Ihe
space
of
floating point arrays
EXAMPLE
10 DIM AS(40).B705).CC%<4.4,4)
41 Elements 16 Elements 125 Elements
You can dimension more than one array In a DIM statement by
separating
the
arrays
by
commas. It the program executes
a
DIM
statement for any array more
lhan once,
you'll
get a
re'DIMed array
error message II is
good
programming practice to place DIM
stalemenls near ihe beginning of the program
DO (LOOP) WHILE (UNTIL EXIT)
DO|UNTIL
boolean argument
| WHILE
boolean arguement)
stalemenls [EXIT]
115