Skip to content
Game 4 Unit 2 of 6 1 hr learning time

Measuring Time

A loop counter measures reaction time — the player gets a number to beat.

33% of Reflex

The player pressed a key. But how fast? Without a number, there is no game.

  10 BORDER 0: PAPER 0: INK 7: CLS
  20 RANDOMIZE
 100 CLS
 110 PRINT "Get ready..."
 200 PAUSE INT (RND * 100) + 50
 220 PRINT "NOW!"
 230 LET t = 0
 240 IF INKEY$ <> "" THEN GO TO 300
 250 LET t = t + 1
 260 GO TO 240
 300 PRINT "Your time: "; t

Three new lines form the timing loop. Line 230: LET t = 0. Line 250: LET t = t + 1. Line 260: GO TO 240. Line 240 changed: instead of looping to itself, it now jumps to 300 (the result) when a key is pressed. Line 300 changed from "You pressed!" to showing the time.

When the player presses a key, t holds how many times the loop ran. Smaller is faster.

Black ZX Spectrum screen reading Your time: 5
The loop counts until you press — your reaction, as a number.

Not real time, but good enough

The number is not in milliseconds — it is in loop iterations. Each iteration takes however long BASIC needs to check INKEY$ and increment t. Not precise, but consistent: the same speed produces the same number.

Run it five times. Watch the number drop as your anticipation improves. That dropping number is the game — you are competing against yourself.