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

A Tower

One block is a brick; a loop is a building. A FOR loop counting up a fixed column POKEs a block at each row, turning one block into a tower of any height.

33% of Skyline

A tower is just one block, stacked. You already know how to place a block by address — so to build a tower, hold the column still and let a FOR loop walk up the rows, placing a block at each.

10 PRINT CHR$(147)
20 POKE 53281,0
30 C=20:H=8
40 FOR R=24 TO 24-H+1 STEP -1
50 POKE 1024+R*40+C,160
60 POKE 55296+R*40+C,12
70 NEXT R
A black C64 screen with a single grey tower rising from the bottom centre.
One FOR loop turns one block into a tower. Change the loop's range and the tower's height changes with it.

The column C stays fixed at 20; H is the height, 8. The loop FOR R = 24 TO 24-H+1 STEP -1 counts up the screen — from the bottom row (24) toward the top, one row at a time, STEP -1 because smaller row numbers are higher up. At each row it POKEs the same block and colour as before. Eight blocks, one above the other: a tower.

Change H to 4 and the tower is short; change it to 15 and it scrapes the sky. That's the power of the loop — one number now controls the whole height.

Try this

  • Build downward by mistake. Swap line 40 to FOR R = 0 TO H-1 and watch the tower hang from the ceiling. Deciding where "the ground" is (row 24) and building up is what makes a city look right.
  • A different shade. Change the colour in line 60 — try 14 (light blue) or 15 (light grey) — and see the tower change material.

What's next

One tower is lonely. In Unit 3 a second loop around this one steps across the screen, raising a tower at each step — a row of towers, from two nested loops.