Don't Oppose Goto - Sharp MZ-80A Owner's Manual

Hide thumbs Also See for MZ-80A:
Table of Contents

Advertisement

32
| Don't
Oppose GOTO
For programs described
so
far, the computer executes
them in the correct sequence from small
to large line numbers.
In fact, however, execution
requires the
sequence
to be
changed
on some
occasions. On such
occasions,
GOTO
state¬
ments
are
very
effective. GOTO means that an unconditional
branch is
made
to
the line number specified.
10 N= I
20 PRINT N
30 N
=
N + 1
40 GOTO 20
50 END
RUN
1
o
Not
stopped?
Press
the SHIFT key, then
BREAK
key to
stop.
Once
upon
a
time,
the
great
Knight Sir Lancelot of the Lake did a
great
deed for King Arthur of Camelot. King
Arthur
was so
greatful
to Sir
Lancelot he said, "I would like
to give you any prize you
care
to
ask
for".
Sir Lancelot replied "Thank you
my Lord,
I would like
to have 1
Ginea
today,
2 Gineas
tommorrow,
4 Gineas on
the 3rd day, 8 Gineas on the 4th
day and
so on
until the 30th day". King
Arthur was so
surprised
by such
a small
request that he agreed immediatly.
Let us make
the program below to find out
how much King Arthur
must
pay.
10 D
=
1
:
F
=
1 : S
=
1
20
PRINT
"DAYS", "GINEAS", "TOTAL"
30 PRINT D,
F.S
40
D=D+1
..........................
This
is
for adding
oneday to each day.
50 F
=
2
*
F
..........................
This
is
for multiplying oneday
's total by two.
60 S
=
S+ F
...........................
This shows the total by
adding to previous day
total.
70 IF D
=
31 THEN 90
80 GOTO 30
90
END
RUN
DAYS
1
GINEAS
1
2
TOTAL
f
1
2
1
3
10
512
1023
20
524288
1048575
30
.
5368709
IE
+
09
.
10737418E+ 10
On
the 10th
day he
was
given
1023
Gineas,
on
the 20th day he
was
given
1048575 on
the 30th day
he asked for
about 1000000000 Gineas.
IF
r

Advertisement

Table of Contents
loading

Table of Contents