Radio Shack TRS-80 User Manual page 69

Micro computer system
Hide thumbs Also See for TRS-80:
Table of Contents

Advertisement

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

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents