Download Print this page

VTech PreComputer 2000 Manual page 31

Advertisement

What happens if you change line 300 to be GOTO 1 0? Yes, you are right. The
program continues
forever.
You can stop it by pressing the
SHIFT
and
BREAK
keys and resume it by typing in CONT and press
ENTER
.
8. LOOPING
A loop is a set of one or more instructions. These instructions can be repeated
as many times as you want
.
You can create a loop with a GOTO statement
.
A program like the following will run forever:
10 INPUT "GIVE ME A NUMBER";N
20 PRINT "YOUR NUMBER
IS";N
30 GOTO 10
You can modify the program to get out of a loop by using an IF statement to
control the loop like the program that calculates the area of a rectangle
.
Another way to create a loop is through the use of the FOR and NEXT
statements.
These statements surround the instructions that you want to repeat.
For example, type the following:
NEW
10 FOR N=1 TO 10
20 PRINT
"HELLO"
30
NEXT N
RUN
How many times does the word HELLO get printed? You can change line 20
to print the value of N every time the loop repeats
.
Type:
20 PRINT "N IS";N
30

Advertisement

loading