For - Sharp PC-1500A Instruction Manual

Hide thumbs Also See for PC-1500A:
Table of Contents

Advertisement

All and more about Sharp
PC-1500
at http:/lwww.PC-1500.info
comparison
of the
methods
used
to
begin a program,
see
the
Chapter
entitled
Beginning Program
Execution).
Unlike the
RUN
command lhe GOTO command
will not clear values
from
any
variables
before it begins execution of lhe program.
To begin program
exerution with the GOTO
command
ENTE
R:
GOTO line·numbcr
where:
line·numbcr
is
the
number
of the
first line ol the program to be
executed.
NOTE:
Specifying
a
line.number
which
does
not
exist
will
result in
an
ERROR 1
1.
P. FOR
and
NEXT
As we
saw in the
previous
section, the
abili
ty to repeat a series
of
instructions
is
very useful.
In
fact
this
feature
is
so ohen
used that
BASIC incorporates several staterllents
to
automate the
process. These are the FOR
statement
and
its
partner, the NEXT statement.
Together,
the FOR
and
the NEXT statements
enclose
a
series of
instructions which are repeated a number
ol
times.
The FOR
statement has
an associated counter
variable and a built·in
test
condition.
It
also allows
the
specification
of
the initial
value and the
increment
value
of the
counter
variable.
The
form for
all
of this information
is:
FOR counter·variablc
~
initial.value TO linal·value STEP
increment·value
where:
counter-variable
is
the
name
of
the
variable used to
hold the
~oop
count.
initlal·value
is
the value
sto:
r ed in the
counter·variablc
before the lir$t
t
ime through
the loop.
The
allowable range
for
this
value is
-
32768
through
32767.
final·value
is
the number which
is
used
in
tho test.
If the counter-variable
contains a va lue
greater
than final·value, the
looping is ended. The
legal
range
for
this
number
is
-
32768
through
32767.
STEP
increment-value is
an
optional
clause.
The
increment·value
indicates
by
how much
to
increase
or decrease
the
counter·variable each
time
t
hrough the
loop.
This must be an
integer
in
the
range
- 32768
through 32767.
II
the entire clause
is omitted, then
the
increment-value
is assumed
to
be one:.
This is
a lo
t
to handle,
so
let's observe
the
behavior of some simple, sample programs. The first
program is similar to the version
of
the
CHUG
CHUG
program
which
used
a
counter.
Instead of
"chugging" we
print
the
value
of the
countcr-varlablu C:
15 FOR C
=
1 TO 10
30
PAUSE C
50
NEXT C
(To make this program "CHUG" as before,
simply insert
statements
10,
20,
and 30 from that
program).
Notice that this version
i$
neater
and
more
concise
using
fe\'1er
statements to
accom·
plish
the
same counting
and looping functions than the
older
version.
In case
there
is
still some •esidual confusion
about what the
FOR
and NEXT
statements
are
doing,
we
present
a oon1parison of a FOR
...
NEXT
loop
with the
oquivalent
statements:
5
1
Do
not sale
this PDF
!!!

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents