45
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
We could always rewrite the program like this:
10 N=1
20 PRINT "N IS";N
30 N=N+1
40 IF N > 10 THEN END
50 GOTO 20
Summary of Contents for PreComputer Prestige
Page 1: ...COURSE BOOK...