“ increment”) your counter—you can decrease (or “decrement”)
it as well. For example, change line 10 in the program above to
read:
10 FOR X=100 TO 0 STEP - 10
The computer will count backward from 100 to 0, in units of 10.
If you don’t use a STEP command with a FOR statement, the
computer will automatically increment the counter by units of 1.
The parts of the FOR-NEXT command are:
FOR
— word used to indicate beginning of loop
X
— counter variable; any number variable can be used
1
— starting value; may be any number, positive or
negative
TO
— connects starting value to ending value
100
— ending value; may be any number, positive
or negative
STEP
— indicates an increment other than 1 will be
used
2
— increment; can be any number positive or negative
Section 5 describes DO/LOOP, a new, more powerful BASIC 7.0
command to perform a similar task to the STEP command.
INPUTTING DATA
The INPUT Command
Assigning a value to a Variable
Clear the computer’s memory by typing NEW and pressing
RETURN, and then type and RUN this program.
10 K=10
20 FOR 1=1 TO K
30 ? “COMMODORE 128”
40 NEXT
ln this program you can change the value of K in line 10 to make
the computer execute the loop as many times as you want it to.
You have to do this when you are typing in the program, before it
is RUN. What if you wanted to be able to tell the computer how
many times to execute the loop at the time the program is RUN?
4-7