Many BASICS give useful ON…GOTO…statements which, unfortunately, ZX/TS BASIC lacks.
Let’s tell our computer ON A GOTO 125, 385, 720. It goes to 720 if A=3. The computer goes to the line which lies Ath in the list.
One way to mimic this command is to substitute IF A=1 THEN GOTO 125, IF A=2 THEN GOTO 385 and so on. These multiple IF statements eat memory, but replacing ON A GOTO with GOTO G(A) can work.
DIMension numeric array G with as many elements as line numbers in the ON…GOTO list; assign each element in G with a line number. Our example uses LET G(1)=125, LET G(2)=385, LET G(3)=720. Do this in immediate mode (with no line number) to save memory, then remember to use GOTO 1 instead of RUN to avoid erasing G.