EasyManua.ls Logo

Radio Shack TRS-80 - Page 69

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...
Nothing to it!
A was printed
5
times
and
B
printed
20
times.
If you are having trouble
counting
A's
and B's as they whiz
by,
you
remember
what
to do. Just press the
(+),
(+)
or
(*•)
key to
stop
execution and
temporarily freeze
the display.
The
I
BREAK)
key and
typing
CONT
do the same
thing,
allowing
hands-off
freezing,
but inserts
a
BREAK
note and other-
wise messes up the
display.
How
to
goof-up
nested
FOR-NEXT
loops
The
most common error beginning
programmers
make with
nested
loops is
improper
nest-
ing.
Change these lines:
50
NEXT A
60
NEXT
B
...
and
RUN.
The
Computer says:
WHAT?
60
NEXT
B?
Looking
at
the
program we quickly see
that the
B
loop
is not nested
within
the A loop. We
have
the FOR part of the B loop inside
the
A
loop,
but the
NEXT part
is outside
it.
This
does not work. A later chapter deals
with something called
"flow
charting", a
means
of
helping
us plan programs and
avoid
this type of problem.
Meanwhile we just
have
to be
careful.
Breaking
out of Loops
Improper nesting is
illegal,
but
breaking
out of a loop
when
a desired
condition
has been
met is OK, Add these lines:
50 NEXT
B
55
IF A
=
2 GOTO 100
60
NEXT A
99
END
100 PRINT "A EQUALLED 2. RUN ENDED."
... and RUN.
67

Other manuals for Radio Shack TRS-80

Related product manuals