Comments (3)
Resolved in:
#39
Thanks pauwell!
from wwwbasic.
I found the following article really interesting:
https://www.atarimagazines.com/compute/issue87/The_Power_Of_ON-GOTO_And_ON-GOSUB.php
It says the following about on..gosubs behaviour in this case:
10 PRINT "ENTER NUMBER : "; : INPUT D
20 PRINT "D = "; D; " : ";
30 ON D GOSUB 40, 50, 60, 70 : GOSUB 80 : GOTO 10
40 PRINT "CAME TO LINE 40 : "; : RETURN
50 PRINT "CAME TO LINE 50 : " : RETURN
60 PRINT "CAME TO LINE 60 : "; : RETURN
70 PRINT "CAME TO LINE 70 : "; : RETURN
80 PRINT "CAME TO LINE 80 : "; : RETURN
When you run this program, it asks you to enter a number. If you enter 1, the program displays the message Came to line 40. After it returns from the subroutine at line 40, notice that the program does not proceed to the routines in lines 40–70. Instead, it proceeds to the next BASIC statement in the line, GOSUB 80. This statement is always performed, allowing you to note the difference between ON-GOSUB and a normal GOSUB command.
Now try entering a number smaller than 1 or greater than 4. Notice how ON-GOSUB responds. In this case, the program skips all of the possible destination lines listed in the ON-GOSUB statement. ON-GOSUB does not cause any branches, and the program proceeds to the next statement (GOSUB 80). For example, if you enter 0 at the prompt, the program prints Came to line 80.
Is this how it should handled here? I read that in some versions of BASIC it results in an error but in most versions it just gets skipped if it is out of bounds.
from wwwbasic.
My offhand reaction is that until we have a more unified place to put compat flags / modes of operation that we'd want to support the most permissive thing (fallthru) as working programs are unlikely to meaningfully rely on erroring in this case.
But this might be a good place for a TODO: Make this behavior configurable once we have BASIC version flags.
In terms of the return behavior, also note that:
10 PRINT "ENTER NUMBER : "; : INPUT D
20 PRINT "D = "; D; " : ";
30 ON D GOSUB 40, 50, 60, 70 : GOSUB 80 : GOTO 10
40 PRINT "CAME TO LINE 40 : "; : RETURN
50 PRINT "CAME TO LINE 50 : " : RETURN
60 PRINT "CAME TO LINE 60 : "; : RETURN
70 PRINT "CAME TO LINE 70 : "; : RETURN
80 PRINT "CAME TO LINE 80 : "; : RETURN
Emits:
hi
hi
there
Where one might have expected:
hi
there
from wwwbasic.
Related Issues (20)
- Support for BASIC dialects HOT 4
- Implement ON x GOTO a,b,c,d HOT 5
- Add a copyright header check. HOT 1
- Some issues found by static analyzer HOT 3
- Implement error on out of bounds array access.
- Implement PLAY and SOUND HOT 7
- Better error handling for FUNCTION/SUB/GOSUB/RETURN clashes + underflow. HOT 3
- Handle touch screen input better.
- Some Guidance on The Why? HOT 3
- Support GORILLAS.BAS HOT 2
- Emulate EGA/VGA PALETTE + CGA Background HOT 1
- Support the ANY type properly HOT 1
- Support EGA/VGA Text 8x14 / 9x16
- Set the input focus in the browser HOT 1
- Add waffle.io project management
- Changing tabs flips wwwBasic window upside down HOT 1
- Basic Anywhere Machine
- A suggested bug-fix for the "swap" statement HOT 1
- BASIC Anywhere Machine: enhancements to internal copy of wwwBASIC
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wwwbasic.