PDA

View Full Version : GOSUB



jjzcp
September 17th, 2005, 08:00 PM
Hi, why is it, in my BASIC book, when i looked up the gosub command it whent like this........

BOOK

10 print "1"
20 print "2"
30 gosub 80
40 print "3"
50 print "4"
60 gosub 80
70 stop
80 print "5"
90 return
run
1
2
5
3
4

and theTandy 1000 goes like this......

10 print "1"
20 print "2"
30 gosub 40: print "3": end
40 print "4"
50 print "5": return
run
1
2
4
5
3

:crazy: :stern: :tellme:

Terry Yager
September 17th, 2005, 09:07 PM
What is the name of the BASIC book you are using?
Back before everything became IBM-compatible, almost every computer on the market used it's own "dialect" of BASIC. The books that were written were designed to be as compatible with as many different dialects as possible, therefore were addressed to the least-common-denominator. Since not all dialects supported multiple commands on a single line, your book was probably written in such a way as to work on almost any dialect. If you try running the first example on your Tandy, it should work, and produce the same output as in the example. OTOH, the second example won't run at all on some vintage equipment, it'll just get to line 30 and then crash because it doesn't understand the meaning of the colon.

--T

jjzcp
September 18th, 2005, 01:45 PM
Hi, the name of the book is " BASIC AND THE PERSONAL COMPUTER" by Thomas Dwyer and Margot Critchfield, and the year published is november 1982. Was 1982 before The IBM BASIC took over, i forgot. :?:

Terry Yager
September 18th, 2005, 02:23 PM
The IBM-PC came out in late 1981, but it didn't really "own" tha market for another year or two. (Of course, if your book was published in '82, it was probably written in '81-or-so).

--T

carlsson
September 18th, 2005, 02:32 PM
I agree with Terry. The two example programs are different and will yield different output. It seems like you're suggesting that most Basics will ignore executing a subroutine the second time it is called (60 GOSUB 80), which is something I've never heard about before.

I have David A. Lien's "Basic Handbook" in a 1981 edition. He does not mention any known strange behavior of the GOSUB command, other than some Basics that are not Microsoft based would also allow the syntax GOSUB N*10+100 to execute a subroutine at the line number the expression evaluates to. It is rather handy on those computers that support it (ZX Spectrum etc), but not an absolute requirement. Most other Basics support ON N GOSUB xx,xx,xx so if the possible values of the expression are known on before hand, it can be rewritten as such. I suppose in your GUI, you will want to use some ON GOSUB mechanism if you want to avoid tons of IF statements for branching.

mbbrutman
September 18th, 2005, 06:05 PM
The book might be flawed. The first program should return output that looks like:



1
2
5
3
4
5


The output of the secon program looks to be correct.

I tested both with GWBASIC 3.27.


Mike

Terry Yager
September 18th, 2005, 06:12 PM
Yeah, I missed the second GOSUB till carlsson pointed it out.

--T