All and more about Sharp P
C-
1500
at
http
:/l
www.PC-1500.info
Unfortunatel
y,
this program wi
ll
just keep
"c
hu
gg
ing
" along forever. (You may stop the
program by using
the
BREAK key).
We
should provide a way for such programs
to
end
.
We
can
do
this
by
using
.a
"cou
nter" along with an IF
statement
. A
coun
te
r is a variable in which we
keep
a
recor
d
of
how many times
we
have
done
some1hing (i.e.
we
count
w
ith
it}. Wilh this
technique
the
IF
stateme
nt
will test whether
we
hove performed
our
PRINT statements a prede1er-
mined number
of
times.
Of
course. it is en
tir
ely
up
to
us
to
determine the number of repetitions.
Let's pick 10 times for each PRINT statement (ah<ir 10 times I gel bored).
Using our counter and IF statement
we
can writ
e:
Program Listing:
10 WAIT
30
15 c = 1
20
PRINT "CHUG
CHUG
CH
f
UG
CHUG"
30
PRINT " CHUG
CIHUG
CH
UG
CH
UG"
40
c = c + 1
50
IFC
< = 10 THE
N20
60
ENO
Keystrokes:
(I)
00
00
OD CD
l!.J
QJ
[.Q.
1 I ••
n•
I
mmm
1 =
JITl
l••r'")
D:J
mm
00
CD CfOCfJ I
"'"
" [.;:J Q;JODfU"J
[];J
1 .... ccJ
m
OD
rn
m
~
Q;J
rn
rn rn
1••
•c•
1 m oo
rn
OD@fil'J r
::.J
IP'ilil
rnrn
mm
co M t
•"
"'
l
rr@
•«
J 1
•••«
11 .
..
"'
1
l
sPA
aj
l
SPAC•
l
a:l
01JWl
...
•C
<
](C]CJDf!Dm
'"''"i
[CJ(ii][U)m
,
......
,
mmCi[J@J
l
...
n l
CJ
lSl
OC
m .
=
~
CCJ
r + J CD I
11•n•
I
mno
m
mm1
.....
1
r
<
~
@
lo:JI
e J
[!J
f H •
moo
rn
C
1[
J ,
....
!J
mwm
rn rn
1 • • ,
..
1
Fo
ll
ow
the o
pe
ration of the counter as each l
oop
is
executed. Notice that
in
line 15 wo must
ass
i
un
the counter
i>n
initial
valu
e. On line
40
we i
nc
rement this
value
to refl
ec
t one more
execu1ion of sta
tements
20
and
30
.
There are
many
other ways to use counters
and
loops within programs. Unfortunately, we
do
not
have
the
space to describe them here.
We
suggest th at you pursue your educati
on
with
one
of
the
books
listed in Appendix F.
The
GOTO instruction is a command
as
well
as
a statement. As a command i
ts
use
is
naturally
different from i
ts
use as a program statement. Issued as a command, in
the
RUN mode, GOTO
begins prog<am e><ccvtion
in a manner similar
to
the
RUN comm
and
.
The
difference lies in certain
internal preparations which are made before instructions of the program are performed.
(For
a
50
Do not sale this PDF !!!