A
ll
and more about Sharp PC-1500
at
http://www.PC-1500.info
comparison
of
the
methods used
to
begin a p
ro
g
ra
m,
see the Chapter entitled Beginning Program
Execution
}.
Un
li
ke
the
RU
N command the GOTO command will
not
clear values from any
variables before
it
b
eg
ins execution
of
the
program.
To
begin program executioll with the GOTO
comma
nd ENTER:
GOTO line·
number
\Vhere:
line·number
is
the
nu
mber
of
the first line
of
the
program
to
be executed.
NOTE:
Specifying a line
·numb
er
whi
ch
does
not
exist will re
sult
in an ERR
OR
11.
P.
FOR
and NEXT
As
we
saw
in
the
previous
section,
tl1e
ability ·to
repeat
a
series
of i
ns
truct
ions
is
very
us
eful. In
lact
th
is
feature is
so
olleri used
that
BAS
IC
in
corpo
rates
sev
eral statement1
to
automate
the
process. These
are
the FOR
statement
and its partner, the NEXT statement.
Toget
he
r.
the
FOR
and
the
NEXT
statements
enclose a series of instructions which are repeated a
number
of
times.
The
FOFI
st
atement
has an a<Sociated
counter
var
ia
ble and a bu
il
t·
in
test condition.
It
also allows
the specification ·of the initial
value
and
t
he
increment
value
of
th
e counter
va
riab
le
,
The
form for all
of
this information is:
fQB.
counte
r.variable = initial·value .IQ final ·value STEP i
rn
crement·value
where:
counter·variab·le
is
the
name of
the
variable used
to
hold
the
l
oop
cou
nt
.
initial-value
is
the
value stored in
the
counter.variable before
th
e first time
th
rough
th
e l
oop
.
The
allowable range for this value
is
-327
68
th rough 32767.
final·value is
the
number
which
is
used in
the
test.
If
the
counte
r-
variable contains a value
greater
than
final-value,
the
looping
is
ended.
The
legal range for
th
is
number
is
-32768
through 32767.
ST
EP increment-value
is
an
opti
ona
l
clause
. The increment-value
inditA1tes
by how much
to
increase or decrease t
he
counter.variable each time through the
loop
.
This
must
be
an
integer in the range -
32768
thro
ugh 32767. If
the
entire clause is omitted.
the
n
the incrcmcnt·value
is
assumed to be
one.
This is a l
ot
to
handle, so let's observe
the
behavior
of
some simple. sample programs.
The
first
program
is
simil
ar
to
the
version
of
the
CHUG
CHUG
pro
gram which used a counter. Instead of
"chugging" we
print
the value
of
the
counter
-variable
C:
15 FOR C = 1 TO 10
30
PAUSE C
50
NEXT C
(To make this program
"CH
UG
"
as
before,
simp
ly
insert
statem
ents 10,
20,
and
30
from that
program). Notice that this
ve
rsion
is
nea
ter and
mo
re conc
ise
using
fe\
-..er
statements to accom·
pl
i
sh
the
sam
e
co
unt
in
g
and
looping functions
th
an
the ol
der
version.
In case there
is
sti
ll
some residual confusion
about
what
the
FOR and NEXT stateme
nts
are
doing, we present a comparison
of
a FOR .
..
NE
XT
loop with
the
equ
iv
alent statements:
51
Do
not sale this PDF
!!!