Multi-Way Branching

See all articles from CATS v3 n2
Author(s): Mike Morris
Publication: CATS Newsletter
Pub Details: CATS v3 n2 (Volume 3, Issue 2)
Date: May 1985
Pages: 13

The need often arises in writing a program to test the value of a variable and then to branch to one of many possible routines depending on the value of the variable. This situation arises in constructing menus for example. Using statements like

IF...THEN GOTO ...

will of course do the job but the 2068 provides a simpler way. The “trick” is that GOTO and GOSUB can be followed by any numeric expression.Thus

GOTO 100+x

will cause a branch to line 150 (or the next line after 150 if 150 does not exist), if x has the value 50. Or, suppose you want to let the user chose one of many alternative actions with mneumonic names.This can be done with a single line:

INPUT A$:GOTO 100+CODE A$

If A$ is “ball”, then CODE A$ will be evaluated as 98 (only the first letter counts) and so the branch will be to line 198. At line 198, of course, you must have the routine to implement the action for “ball”.If the user inputs “bat” he will get the same action as “ball” since both strings start with the same letter.

Mike Morris

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.