This is a cache of https://vccplus.brianholman.com/manuals/programming-in-coco-basic/find-the-leak/. It is a snapshot of the page as it appeared on 2026-11-21T00:00:53.914+0000.
Find the missing supply · Programming in CoCo BASIC on the Color Computer 3 · VCC Plus
← Manual LibraryVCC Plus 3.7.1 · Reading on the web

Try the exercises in VCC Plus. Example links download files here; open them in the app to work beside the emulator.

The complete book · PDF editionBook 3: Programming in CoCo BASIC on the Color Computer 3

79 pages · VCC Plus 3.7.1 · Keep a copy to read or print.

Download PDF
Contents

Chapter 4 of 12

Find the missing supply

Some bugs make BASIC stop and print an error. This one is trickier. Every line is legal BASIC, the ship makes all three turns, and the crew ends up hungry.

Reproduce the fault

Open LEAK.bas and choose Run. You’ll see 4, 2 and 0 supplies left after the three turns. In chapter 3 the same six packs lasted the whole trip with three to spare. Where did the first extra pack go?

10 WIDTH 40:CLS
20 S=6
30 FOR T=1 TO 3
40 S=S-1
50 S=S-1
60 PRINT "TURN";T;" SUPPLIES";S
70 NEXT T
80 END

BASIC is quick enough to finish the flight before you can read the first result. Use a breakpoint to ask the editor to wait for you at a particular instruction. That lets you investigate while the clues are still in RAM.

Stop before the subtraction

  1. In the editor, click the breakpoint circle in the margin beside 50. To set it from the keyboard, put the insertion point on that line and activate Toggle BASIC breakpoint at insertion point.
  2. Open Variables and Watches. Select Watches, add S, then add T. The editor will fill in their values when BASIC stops.
  3. Choose the editor’s Run again. The highlight should land on line 50. Read both watches before doing anything else. T is 1. S is already 5. Line 40 has spent one pack. Line 60 has yet to print the first turn.
  4. Choose Step Into BASIC statement once. The highlight moves to line 60. Read the watches again. T is still 1. S is now 4. One crew, one turn, two subtractions. You found the leak.
Before line 50 runs, the Watches list shows S at 5 and T at 1. The first turn is still in progress.
One step later, line 60 is highlighted. S has fallen to 4 while T is still 1.

The highlighted instruction is the next one BASIC will carry out. That small detail makes the screen and the watches agree: at the second stop S is 4, but the print instruction that will display it is still ahead.

Choose Continue. Line 60 prints the first result, NEXT moves T on, and the breakpoint catches the next trip through line 50. Choose Continue twice more to finish the three turns. You can use the Variables tab to inspect everything BASIC has created. A watch lets you pick a few names and keep your attention on them.

Repair the listing

Finish the run before editing. Click the breakpoint circle again to remove it. In your editable example, delete the entire line 50 S=S-1. Keep line 40. Run the edited copy. You should see 5, 4 and 3. RATIONS.bas is the supplied repaired version if you want to compare. The gap between 40 and 60 costs the CoCo nothing.

Three kinds of stop. A breakpoint belongs to this editor document. Step Into carries out one BASIC statement. Continue runs until another stop or the end. BASIC also has a STOP statement and a CONT command of its own. A new run or a changed program can make guest continuation impossible. When BASIC reports a short error code and line number, use Show Line in the editor to inspect that statement and the error guide to look up the code. TRON and TROFF are the older guest tools for printing a trace of line numbers as BASIC runs.

When a step waits for you

A BASIC statement that asks for input can still be running while you look at the editor. Pause BASIC step appears during a pending step. A mid-statement pause can have no highlighted source statement because the interpreter has yet to reach the next one. Choose Continue and focus the CoCo display to answer the waiting program. The debugger can step from a statement boundary again when it reaches a BASIC breakpoint.

A runtime error leads somewhere different. In the error banner, Show Line takes you to the numbered statement. The question-mark button, Explain this BASIC error, opens its entry in the local Quick Reference. The failed run has ended. Correct the source and run again when you are ready. To remove the document's stops together, use Editing → Clear All Breakpoints.

Move a line and keep its address

Line numbers are also destinations. In HELM, the bad-reply path jumps to 40 for another question. If you changed that label by hand and forgot the jump, the next bad reply would go looking for the old number.

For a small experiment, open HELM.bas again and run it. Enter 2 to reach the guest prompt. Type RENUM 100,0,10, then LIST. You asked BASIC to start the new numbers at 100, begin with the old lines from 0 onward, and leave a gap of ten. The old line 80 now reads 170 GOTO 130. The question has moved to 130, and the jump followed it. Enter RUN and 1 to try the renumbered menu. Look for BOUND FOR EARTH.

That change happened in guest RAM. To bring it back to the Mac, use Read from CoCo. To renumber an editor copy instead, use Editing → Renumber…, choose the first number and increment, and apply the change. ⌘Z undoes that edit before transfer. This distinction lets you try out new numbering on one side while keeping a saved copy on the other.

Original VCC Plus manuals © 2026 Brian K. Holman. Third-party references retain their authors’ copyrights and licenses. Artwork notices. Edition 3.7.1; source and export identity. Printable edition: PDF source and export identity.

A closer look

Open original