EasyManua.ls Logo

Radio Shack TRS-80 - Page 51

Radio Shack TRS-80
236 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Note
that
in
this
system
of
incrementing
and testing
we do not send the
program
back to
line 8 as
was the
case
with FOR-NEXT.
What
would happen if we did?
Answer:
We
would keep re-initializing the value
of
N to
equal
1,
and would again form an
endless loop.
The
opposite of
incrementing
is decrementing.
Change the program so line 15
reads
15 N
=
N
-
1
. . . then
make other changes as
needed
to make the program work.
Answer: The changed lines read:
8
N
=
6
15 N
=
N
-
1
20 IF
N> 1 THEN 10
Putting
FOR-NEXT
to
work
It isn't very exciting
just seeing or doing the same thing
over and over,
so
there has
to be a
more noble purpose
for the FOR-NEXT loop. There
are
many
of them, and we will be
learning
new uses
for
a long, long time.
Let's suppose we want
to
print
out a
chart
showing
how the time
it takes to fly from Boston
to
San Diego varies with the speed at
which
we
fly.
Remember, the formula is D
=
R*T.
Let's print
out the flight time required
for each
speed
between
200
niph and
1000
mph,
in increments of
200
mph. The
program
might look
like
this:
10 REM
*
TIME
VS
RATE
FLIGHT
CHART
*
20
CLS
irs
!
.i;is«jH|||ii..
.
.
.
.:,
-.
To decrement
is
to make smaller.
49

Other manuals for Radio Shack TRS-80

Related product manuals