Empty Loops-Inserting Delays In A Program; The Step Command - Commodore 128 System Manual

Hide thumbs Also See for 128:
Table of Contents

Advertisement

Empty loops—Inserting delays in a program
Before you proceed any further, it will be helpful to understand
about loops and some ways they are used to get the computer to
do what you want. You can use a loop to slow down the
computer (by now you have witnessed the speed with which the
computer executes commands). See if you can predict what this
program will do before you run it.
10 A$=" COMMODORE 128"
20 FOR J=1 TO 20
30 PRINT
40 FOR K=1 TO 1500
50 NEXT K
60 PRINT A$
70 NEXT J
80 END
Did you get what you expected? The loop contained in lines 40
and 50 tells the computer to count to 1500 before executing the
remainder of the program. This is known as a delay loop and is
often useful. Because it is inside the main loop of the program, it
is called a nested loop. Nested loops can be very useful when
you want the computer to perform a number of tasks in a given
order, and repeat the entire sequence of commands a certain
number of times.
Section 5 describes an advanced way to insert delays through
use of the new BASIC 7.0 command, SLEEP.

The STEP Command

You can tell the computer to increment your counter by units (e.g.
10, 0.5 or any other number). You do this by using a STEP
command with the FOR statement. For example, if you want the
computer to count by tens to 100, type:
10 FOR X=0 TO 100 STEP 10
20 ? X
30 NEXT
Notice that you do not need the X in the NEXT statement if you
are only executing one loop at a time—this is discussed later in
this section. Also, note that you do not have to increase (or
4-6

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

128d

Table of Contents