EasyManua.ls Logo

Radio Shack TRS-80 - Page 50

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...
We
now
have a
program
with
two
controlled
loops,
sometimes
called
DO
loops. The
first
do-loop
DOES
something
five
times;
the
second
one
does
something
three
times. We
used
the
letter
N
for the first
loop
and
M for
the
second,
but
any
letters
can
be
used. In
fact,
since
the
two
loops
are
totally
separate we
could
have
used
the
letter
N for
both of
them
-
not
an
uncommon
practice
in
large
programs
where most
of
the
letters
are needed
as
variables.
RUN
the
program,
being
sure
you
understand
the
fundamental
principles
and the
varia-
tions
we
have
introduced.
From>to
Incrementing
There
is
nothing
magic
about
the
FOR-NEXT
loop, in
fact, you
may
have
already
thought
of
another
(longer)
way
to
accomplish
the same
thing by
using
features
we
learned
earlier.
Stop
now,
and
see if
you
can
figure out a
way
to
construct
a
workable
do-loop
substituting
something
else in
place
of
FOR
and NEXT.
Answer:
8
N
=
1
10 PRINT
"HELP
MY
COMPUTER
HAS GONE
BERSERK!"
15
N
=
N
+
1
20 IF N<6
THEN 10
30
PRINT
"NO
IT'S
UNDER
CONTROL
.
"
We say
that
line 8
initializes
the
value of N,
giving
it an
initial
or
beginning
value of
1.
Be-
fore
initializing
to
the
value we
want, N
could
have
been
any
number
left
over
from
a
pre-
vious
program.
Line 15
then
increments
it by 1,
making
N
one
more
than
whatever
it was
before.
Line
10
uses one
of
our
relational
operators,<,
to
see
that the
new value
of N
is within
the
bounds
we have
established.
If
not,
the
test fails
and the
program
continues.
48
Initializes
initially, or
at
the beginning, sets the
value
of one of
our variables
{
or
starts
a
program
baek atthe
beginning).
Increments
steps
(Increases or
decreases values
in specific
stepsi
by
%%
3%:
5
V,'
or
whatever).
":"•;

Other manuals for Radio Shack TRS-80

Related product manuals