EasyManua.ls Logo

Radio Shack TRS-80

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...
Chapter
10
From >to
FOR-NEXT ...
or
SMART
Loops
A
major
difference between the computer and a calculator is the computer's ability to do
the
same
thing
over and over
an
outrageous number of times, faster than a speeding bullet
(to
coin a
phrase)! This one capability more than
any
other, separates the two.
The
FOR-NEXT
loop is of such overwhelming importance in putting our Computer
to
work, that
few of the programming areas we will
explore
from this point on will exclude
it. Its
simplicity and
variations
are the heart of its
effectiveness,
but its power is truly
staggering.
Type
in the following program,
andRUN
:
10 PRINT
"HELP
MY COMPUTER HAS GONE BERSERK!"
20 GOTO
10
You
have noticed by
now
that the Computer is continuously writing the line
HELP
MY
COMPUTER HAS GONE
BERSERK
!
It will continue
to
do
so indefinitely until you
tell it to stop. When you have
seen enough,
hit the
|BREAKj
key.
What we
created
is
called an "endless loop", (Remember our earlier
programs
which kept
coming back for more INPUT?) Line
20
is an unconditional GOTO
statement which
causes
the Computer
to
cycle
back and forth ("loop")
between lines
10
and
20
forever if not halt-
ed. This idea has great potential if
we
can harness it.
Let's
modify the program to read:
8 FOR N
=
1 TO 5
10 PRINT
"HELP
MY COMPUTER HAS
GONE
BERSERK!"
20 NEXT N
30
PRINT
"NO
IT'S
UNDER
CONTROL."
and
it.
45

Other manuals for Radio Shack TRS-80

Related product manuals