Translating Programs: ON…GO TO

Author(s): Mort Butler
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v3 n3 (Volume 3, Issue 3)
Date: March 1982
Pages: 3

Revising some programs for use on your ZX80/81 requires total knowledge of that computer language and its usage. One such term that you will stumble over is the ON…GO TO or ON…GO SUB statement. A program line might read:

  90 ON X GO TO 100,10,333,2000,59

The computer compares the value of X with the line. If X=1 then it will GO TO line 100, if X=2 then line 10, if X=3 then line 333, etc. The same thing will happen if the line reads:

  90 ON X GO SUB 100,10,333,2000,59

Notice that if X does not equal any number 1-5, the computer moves to line 91. In other words, if X equals a negative number, zero, or a number greater than 5, the computer skips that line.

One revision method is to list the numbers:

  90 IF X=1 THEN GOTO 100
91 IF X=2 THEN GOTO 10
92 IF X=3 THEN GOTO 333

If you use GO SUB instead of GOTO, check for RETURN statements. For instance, if line 92 reads IF X=3 THEN GO SUB 333, then a line following line 333 must have a RETURN statement.

A second revision method is the COMPUTED way, like 90 GO TO X*100. If X=3, the computer goes to line 300. Using this method, the computer will go to any value of X (it will even search for a negative line number).

A third revision method is the DIM-ARRAY way, using a dimensioned array containing the line numbers. See SYNTAX (Dec.81 p.18) for this type of data storage.

The computed method uses the fewest bytes and runs at the slowest speed, since it must compute each GO TO. The listed way is somewhat faster. The array method is quick if the DIM statement is near the beginning of the program.