Commodore VIC-20 User Manual page 131

Hide thumbs Also See for VIC-20:
Table of Contents

Advertisement

END
When the program hits a line with the END statement, the program
stops RUNning as if it ran out of lines. You may use the CONT com
mand to re-start the program.
FOR...TO...STEP
This statement works with the NEXT statement to set up a section of
the program that repeats for a set number of times. You may just
want the VIC to count up to a large number so the program will pause
for a few seconds, or you may need something counted. These are
among the most commonly used statements in BASIC.
The format of the statement is as follows:
FOR (loop variable name) = {start of count) TO (end of count). The
loop variable is a variabie which will be added or subtracted to during
the program. The start of count and end of count are the limits to the
value of the loop variable.
The logic of the FOR statement is as follows. First, the loop variable
is set to the start of count value. The end of count value is saved for
later reference by the VIC. When the program reaches a line with the
command NEXT, it adds one to the value of the loop variable and
checks to see if it is higher than the end of loop value. If it is not
higher, the next line executed is the statement immediately following
the FOR statement. If the loop variable is larger than the end of loop
number, then the next statement executed will be the one following
the NEXT statement.
EXAMPLE:
10FORL = 1TO10
20 PRINT L
30 NEXT L
40 PRINT "I'M DONE! L = "L
This program will print the numbers from one to ten on the screen,
followed by the message I'M DONE! L=11. Do you see why it works?
If not, try re-reading the paragraph before the example again, and
tracing through the program one step at a time on paper.
The end of loop value may be followed by the word STEP and another
number or variable. In this case, the value following the STEP is
added each time instead of one. This allows you to count backwards,
by fractions, or any way necessary.
121

Advertisement

Table of Contents
loading

Table of Contents