Skip to content
Game 4 Unit 7 of 8 1 hr learning time

Five Rounds

Wrap the game in a FOR loop for five rounds with a move counter and running total.

88% of Hot And Cold

Finding one treasure feels good. But one round isn’t a game — it’s a puzzle with a single answer. Wrap it in a loop of five rounds with a running move total, and suddenly there’s strategy: do you play it safe and methodical, or take risks to keep your total low? Can you find all five treasures in fewer moves than last time?

Five Rounds with FOR/NEXT

  19 LET tm=0
  20 FOR n=1 TO 5
  27 LET m=0
  28 PRINT AT 21,0; INK 5;"Round ";n;"  Moves: 0    Total: ";tm;"  "
 108 LET tm=tm+m
 110 PRINT AT 21,0; INK 4; BRIGHT 1;"Found! ";m;" moves  Total: ";tm;"    "
 112 PAUSE 75
 114 PRINT AT r,c;" "
 116 BORDER 0
 118 NEXT n

The outer FOR n = 1 TO 5 loop wraps the entire game. Each round:

  1. Resets the move counter to 0
  2. Picks a new random treasure position
  3. Resets the cursor to the centre
  4. Runs the game loop until the treasure is found
  5. Adds the round’s moves to the running total
  6. Pauses so the player can read the result

After the treasure is found, NEXT n advances to the next round — a fresh treasure, a fresh position, the same running total. After round 5, the loop ends and the program falls through to whatever comes next. Right now that’s nothing — the game just stops. The next unit fixes that with a proper results screen.

The Move Counter

Variable m starts at 0 each round (line 27). Every key press adds 1 (line 62):

LET m = m + 1

The status line at row 21 updates with each move, so the player can see their count climbing in real time.

Running Total

Variable tm accumulates moves across all rounds. When the treasure is found, line 108 adds the round’s moves:

LET tm = tm + m

The status line shows both: “Round 2 Moves: 7 Total: 14”. The player can track their overall performance as they play.

Nested Loops

The FOR n loop contains the game loop — but the inner loop isn’t a FOR/NEXT. It’s a GO TO loop that breaks out when the treasure is found. The NEXT n on line 118 advances to the next round.

This pattern — a FOR loop containing a game loop that exits with GO TO — is common in multi-round games. The FOR handles round counting automatically, while the inner loop runs as long as the gameplay needs.

The Pause

Line 112 adds PAUSE 75 after each round. Without it, the screen clears instantly and the player never sees their result. 75 frames is about 1.5 seconds — enough to read “Found! 12 moves” before the next round begins.

Try This

Show moves live. The status line already shows the move count. Try adding the distance too: PRINT AT 21, 25; d; " ". It makes the game easier but helps you understand the distance calculation.

Best round. Add a variable b = 999 at the start. After each round, IF m < b THEN LET b = m. Show the best round at the end.

Three rounds. Change the FOR loop to FOR n = 1 TO 3 for a quicker game during testing.

What You’ve Learnt

  • FOR wrapping a gameFOR n = 1 TO 5 runs five rounds automatically
  • Move counterLET m = m + 1 each time the player moves
  • Running totalLET tm = tm + m accumulates across rounds
  • PAUSE — gives the player time to read results before the screen clears