6 Branching and Subroutines
GOTO line id
Here is an example using GOTO to branch to both higher-numbered and lower-numbered lines:
10 Name$="Gwendolyn" 20 GOTO Print 30 INPUT "NEW NAME?";Name$ 40 GOTO Compute 50 Print: PRINT "NAME IS:";Name$ 60 GOTO 30 70 Compute: ! Continue program. . . .NOTE: A GOTO with line number is not recommened and doesn't work in the IDE.
ON numeric expression GOTO line id list
The numeric expression is evaluated and rounded to an integer. A value of 1 causes control to be transferred to the first statement specified in the list, a value of 2 causes control to be transferred to the second statement specified in the list, and so on. For example:
10 INPUT "IS ITEM OVERSTOCKED(1), OK(2),OR OUT OF STOCK(3)?";Status 20 ON Status GOTO 30,Ok,Reorder 30 Over: ! Overstock routine. . . . 70 STOP 80 Ok: ! 90 PRINT "CHECK ITEM NEXT TIME." 100 STOP 110 Reorder: ! Reorder routine. . . .If the value of the numeric expression is less than 1 or greater than the number of line ids listed, ERROR 19 (improper value) occurs. For example, when line 130 in the next sequence is executed for the fourth time, the value of I exceeds the number of line ids in the list.
120 I=1 130 ON I GOTO Print,Print,Print 140 Print: PRINT "I=";I 150 I=I+1 160 GOTO 130 170 END I= 1 I= 2 I= 3 ERROR 19 IN LINE 130