•
•
••
The program pauses
at
line
30
and you should type the number
of
pens you want, say
Do
not forget the
ENTER
key.
The output will be:
60
The
INPUT
statement needs a variable name so that the system knows where to put
the data which comes
in
from your typing
at
the keyboard. The effect of line
30
with
your typing
is
the same
as
a
LET
statements effect.
It
IS
more convenient for some
purposes when Interaction between computer and user
is
desirable. However, the
LET
statement
and
the
INPUT
statement are useful only for modest amounts
of
data.
We
need something else
to
handle larger amounts at data without pauses
in
the execution
of the program.
SuperBASIC, like most BASICs, provides another method of Input known as READing
from
DATA
statements.
We
can retype the above program
In
a new form to give the
same effects without any pauses.
Try
this:
NEW
..
"
10
READ
price,
pens
..
"
20
LET
cost
=
price
* penS_Ill
30
PRINT
cosh",
40
DATA
15,4
..
"
RUN_II
The output should be:
60
as before.
Each time the program
is
run, SuperBASIC needs to be told where
to
start reading
DATA
from. This can either be
done
by typing RESTORE followed by the
DATA
line number
or
by typing
CLEAR.
Both these
commands
can also
be
inserted at the start of the
programs.
When line
10
is
executed the system searches the program for a
DATA
statement.
It
then
uses the values
,n
the
DATA
statement for the variables
In
the
READ
statement
in
exactly
the same order.
We
usually place
DATA
statements at the end of a program. They are
used by the program but they are not executed
in
the sense that every other line
is
executed
In
turn.
DATA
statements can
go
anywhere
In
a program but they are best
at the end, out of the
way.
Think of them as necessary
to,
but not really part
of,
the
active program. The rules about
READ
and
DATA
are as follows:
1.
All
DATA
statements are considered to
be
a single long sequence of Items. So
far these items have been numbers but they could
be
words
or
letters.
2.
Every time a
READ
statement
is
executed the necessary Items are copied from
the
DATA
statement into the variables
named
in
the
READ
statement.
3. The system keeps track
of
which items have been
READ
by means of an internal
record.
If
a program attempts to
READ
more items than exist
in
all
the
DATA
statements
an
error will
be
signalled.
You
have used names for 'pigeon holes' such as dogs, bars.
You
may choose words
like these according
to
certain rules:
A name cannot include spaces.
A name must start with a
letter.
A
name
must
be
made
up
from letters, digits,
$,
%,
_(underscore)
The symbols
$,
% have special purposes, to
be
explained
later,
but you can use
the underscore to make names such
as:
dog_food
month_wage_total
more readable.
12/84
Instructing
the
Computer
IDENTIFIERS
(NAMES)
11