Skip to content

Commit 9ea085f

Browse files
committed
feat: add ON GOTO and ON GOSUB examples
1 parent 97f316a commit 9ea085f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

Diff for: examples/on_gosub.bas

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <input.bas>
2+
3+
10 PRINT "Enter a number from 0 to 9"
4+
PRINT "Only values 0, 1 and 2 will"
5+
PRINT "be dispatched"
6+
PRINT "> ";
7+
LET X$ = INPUT(1)
8+
IF X$ < "0" or X$ > "9" THEN GOTO 10
9+
20 LET ok = 0
10+
ON VAL(X) GOSUB 50, 100, 150: IF ok THEN END
11+
GOTO 10
12+
30 PRINT "Invalid choice: "; X
13+
40 RETURN
14+
50 PRINT "You chose option 0": LET ok = 1
15+
60 RETURN
16+
100 PRINT "You chose option 1": LET ok = 1
17+
110 RETURN
18+
150 PRINT "You chose option 2": LET ok = 1
19+
160 RETURN
20+

Diff for: examples/on_goto.bas

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <input.bas>
2+
3+
10 PRINT "Enter a number from 0 to 9"
4+
PRINT "Only values 0, 1 and 2 will"
5+
PRINT "be dispatched"
6+
PRINT "> ";
7+
LET X$ = INPUT(1)
8+
IF X$ < "0" or X$ > "9" THEN GOTO 10
9+
20 ON VAL(X) GOTO 50, 100, 150
10+
30 PRINT "Invalid choice: "; X
11+
40 GOTO 10
12+
50 PRINT "You chose option 0"
13+
60 END
14+
100 PRINT "You chose option 1"
15+
110 END
16+
150 PRINT "You chose option 2"
17+
160 END
18+

0 commit comments

Comments
 (0)