Giter Club home page Giter Club logo

Comments (3)

flagxor avatar flagxor commented on May 21, 2024 1

Resolved in:
#39

Thanks pauwell!

from wwwbasic.

pauwell avatar pauwell commented on May 21, 2024

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.

flagxor avatar flagxor commented on May 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.