42
2. 3. 5. 3 INPUT .
................................
(abbreviated format: 1.)
Format
Function
(
numeric variable
INPUT string variable
l array element
INPUT
A
INPUT
8$
I
NPUT
XC
5 )
· ( numeric variable l
...
or
INPUT "character string
11
; string variable J ...
array element
INPUT
" DATA
A=
"
;A
INPU
T "
YES
OR
NO
"
;8$
I
NPUT
" KEY IN " ; XC 5 )
INPUT is one
of
the
statements which is used for entering values for assignment
to
variables during program execution. Program execution pauses when an INPUT
statement
is encountered
to
allow values
to
be
typed
in from
the
keyboard.
After
input
has been completed,
the
values are substituted
into
specified variables by
pressing
the
I
CRI
key,
then
program execution resumes.
(Example:)
1 0
INPUT
A.
B
2 0
C
=A+B
3 0
PRINT
c
4 0
END
When
the
program above
is
executed, a question mark
is
displayed and
the
cursor
blinks
to
indicate
that
the
computer
is
waiting for
data
input;
enter
any arbitrary
number,
then
press thel
CRi
key. This assigns the value entered
to
variable
A.
After
doing this,
the
question mark will be displayed again. The reason for this
is
that
two variables (A and
B)
are specified in the INPUT
statement
on
line I 0,
but
only one value has been entered
(that
which
is
substituted
into
variable A).
Enter
another
arbitrary
number
and press
the
I
CRI
key again; this substitutes
the
second value
ent~red
into variable B and causes execution
to
go
on
to
the
next
line
of
the
program.
In
the
example above, subsequent lines add
the
values
of
A
and
B,
substitute
the
result
into
C,
then
display
the
contents
of
C.
Since
the
variables used in this example are numeric variables,
the
computer
will
display the message ILLEGAL DATA
ERROR
if
an
attempt
is
made
to
enter
any
characters
other
than
numerics.
The
question mark is
then
redisplayed
to
prompt
the
user
to
reenter
a legal value
(a
value whose
type
is
the
same
as
that
of
the
varia-
ble
or
array element
into
which it
is
to
be
substituted).
Be
sure to
enter
data
whose
type
matches
that
of
the
variable(s) specified in
the
INPUT
statement
.
During program execution,
it
may be difficult
to
remember what
data
is
to
be
entered when
the
question mark
is
displayed; therefore,
prompt
strings are usually
included in
INPUT statements for display
on
the screen
as
a reminder. This
is
done
as
shown in
the
program example below.
1 0
I
NPUT
"A= "
;A
2 0
INPUT
"
B=
"
;8
3 0
PRI
NT "A
+B=
" ; A
+B
4 0
PRI
NT " A
-8=
"
;A
-B
50
P R I NT "
A::K
B=
"
;A
)!(B
6 0
PRI
NT "A/ 8 = "
; A/ 8
7 0
END