Skip to content
Game 0 Unit 2 of 15 1 hr learning time

The Line Number Is an Address

Edit a program by its line numbers — replace a line by reusing its number, slip a new line into a gap, delete one, and LIST them in order. The number is the line's address, and that is the whole of editing.

13% of Meet BASIC

In Unit 1 your two lines were numbered 10 and 20, and they ran in that order. The number isn't only a label for where a line sits in the running order — it's the line's address. Once you can write to an address, you can edit: replace what's there, slip something new in beside it, or take it away.

Milestone 1 — a numbered program

  10 PRINT "one"
  20 PRINT "two"
  30 PRINT "three"

Three lines, numbered in tens. Type them in and RUN: they print one, two, three, in number order, and the report reads 0 OK, 30:1 — it reached line 30.

The Spectrum screen showing one, two, three on three lines, with the report 0 OK, 30:1.
Three lines, run in number order. The gaps between 10, 20 and 30 are about to earn their keep.

Notice the numbering jumps in tens. Nothing forces that — 1, 2, 3 would run the same. The tens leave room between the lines, and the next milestone shows why.

Milestone 2 — slip a line into the gap

You want a line between two and three, without retyping anything. Give it a number that falls in the gap — 25, sitting between 20 and 30:

Step 2: type line 25 on its own
+1
11 10 PRINT "one"
22 20 PRINT "two"
3+ 25 PRINT "...and a half"
34 30 PRINT "three"
45

Type line 25 and press Enter — on its own, with the other lines already in place. You don't move anything; the Spectrum files it by number. RUN, and the new line lands exactly where its number puts it: after 20, before 30.

The Spectrum screen showing one, two, ...and a half, three — the new line sits between two and three.
Line 25 lands between 20 and 30 — slotted in by its number, with nothing else touched. This is why we number in tens.

Milestone 3 — write to an address that's taken

Use the same idea to replace a line. Type line 20 again, with new text. The number is already taken, so the new line takes the old one's place:

Step 3: retype line 20 to replace it
+1-1
11 10 PRINT "one"
2- 20 PRINT "two"
2+ 20 PRINT "two (replaced)"
33 25 PRINT "...and a half"
44 30 PRINT "three"
55
The Spectrum screen showing one, two (replaced), ...and a half, three.
Same number, new text — line 20 is overwritten. Writing to an address that already holds a line replaces it.

That's the whole rule, two ways: pick a free number to add a line; reuse a number to replace one. To remove a line, type its number alone and press Enter — line gone.

To see the program in its true order at any time, type LIST. The Spectrum shows every line from lowest number to highest — the order it will run, whatever order you typed them in.

When it doesn't work

  • A new line overwrote one you wanted to keep. You reused a number that was already taken. LIST first, find a free number in a gap (like 25), and add there instead.
  • The line ran in the wrong place. The number decides the order, not where you typed it. Whatever should come first needs the lowest number.
  • You meant to delete a line but cleared the screen, or vice versa. Deleting a line is its number then Enter; clearing the screen at run time is CLS. They're different.

Before and after

You started with three lines and ended having inserted one into a gap and replaced another — without ever retyping the whole program. The idea underneath: a line number is an address. Write to a free one to add; write to a taken one to replace. Numbering in tens keeps gaps open for the lines a later step will add — a habit every program here leans on.

Try this

  • Fill another gap. Add line 15, between 10 and 20. Predict where it prints before you run it.
  • Delete and confirm. Remove line 25 (type 25, Enter), LIST to confirm it's gone, then RUN.
  • Run out of room on purpose. Try to fit two lines between 20 and 25. You can — 21 and 22 — but you'll feel why tens are roomier than ones.

What you've learnt

  • A line number is the line's address.
  • Reuse a number to replace a line; pick a free number to add one; type a number alone to delete it.
  • LIST shows the program in number order — the order it runs.
  • Number in tens so there's always a gap to slip a line into later.

What's next

You can write, run, and edit a program now. Time to make it say more than a fixed word. In Unit 3 we give PRINT its punctuation — joining text and numbers, spacing them, and laying them out.