Re: GOSUB
jjzcp said:
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
I'm not much of a BASIC programmer, but I'll give it a shot, since I don't have a real life either...
Some of your older BASIC dialects didn't support more than one command on a single line, but the T1K running GW-BASIC does, provided the commands are separated with colons. When you give the gosub command, it immediatly jumps to the target line and executes the subroutine there, command-by-command, then line-by-line, until it encounters the RETURN command, at which point, it jumps back to the origin, then executes any other commands found on that line before moving on to the next line.
In the T1K example you've given, the subroutine starts on line 40, then executes the first command on line 50, then the second command on that same line, which is the RETURN command, where it jumps back to line 30 and continues to execute the other command on that line. In other words, your program is doing exactly what you told it to do.
Hope all that makes sense to you, I'm even less of a technical writer than I am a programmer.
--T