Timing Is Everything
What you'll learn:
- Use `FOR...NEXT` loops to repeat instructions predictably.
- Control pacing with loop ranges, `STEP`, and simple delays.
- Combine loops with `PRINT` to build rhythmic screen effects.
Lesson 2 – Timing Is Everything
You made the C64 talk. Now you’ll teach it rhythm. Loops let you repeat instructions without retyping them, keeping the machine busy while you direct the tempo like a bedroom DJ in 1984.
[📷 suggested: photo of a C64 counting numbers across the screen]
The One-Minute Tour
FOR...NEXT
repeats a block of code a set number of times.STEP
changes how much the loop variable increases (or decreases).- Short loops double as “delay lines” that give the eye time to catch up.
Example Program
NEW
10 FOR I=1 TO 10
20 PRINT I
30 NEXT I
Sample output:
1
2
3
4
5
6
7
8
9
10
READY.
Line 10 starts a loop, telling BASIC to make I
walk from 1 to 10.
Line 20 prints the current value.
Line 30 sends control back to the top until I
has reached 10, then the loop stops automatically.
Tip: BASIC doesn’t care about the letter you choose.
I
,J
, andK
are classics, butFOR BEAT=1 TO 8
works just as well.
Experiment Section
- Change the limit: swap
10
for20
and watch the screen scroll faster. - Add a
STEP
:FOR I=0 TO 100 STEP 10
prints 0, 10, 20…100. - Count backwards:
FOR I=10 TO 1 STEP -1
. - Add a pause:
FOR WAIT=1 TO 300: NEXT WAIT
between prints slows the action. - Create a ticker:
PRINT I;
keeps numbers on one line so the cursor marches across the screen.
[🎥 suggested: clip of forward and backward loops running in succession]
Concept Expansion
Loops are the backbone of every future lesson. Next time we’ll add IF
so loops can decide what to do mid-flight. Down the line you’ll nest loops to draw grids, animate sprites, and time music routines.
Game Integration
- Countdown timers:
FOR T=5 TO 1 STEP -1
before launching a rocket animation. - Scoreboard updates: loop over rows to refresh the HUD each frame.
- Screen wipes: loop through colour changes to “fade” between scenes.
From the Vault
- Commodore 64 — learn how the 1 MHz 6510 sets the pace for every loop you write.
Quick Reference
REM Loop essentials
FOR var=start TO end [STEP value]
<statements>
NEXT var
- Default
STEP
is 1. - Loop variable keeps its final value after
NEXT
. - Use trailing semicolons (
PRINT value;
) for inline output.
What You’ve Learnt
FOR...NEXT
repeats instructions without copy-paste gymnastics.STEP
changes loop direction and speed.- Simple loops double as timing tools, pacing output for human eyes.
- You can already build countdowns, tickers, and simple screen wipes.
Next lesson: Decisions, Decisions — add IF/THEN
so the C64 chooses its own adventure.