|
Post by carlgundel on May 13, 2020 16:35:09 GMT
Indeed we cannot. Recursion works by using local variables for all called copies of SUB. GOSUB/RETURN have no local variables, at all. You can if you are willing to use arrays to manage state. Or if you cleverly use a string to do something similar.
|
|
|
Post by honkytonk on May 13, 2020 17:16:33 GMT
You can if you are willing to use arrays to manage state. Or if you cleverly use a string to do something similar. Ah, so it is possible, I will study in this direction.
|
|
|
Post by B+ on May 13, 2020 21:44:16 GMT
You can if you are willing to use arrays to manage state. Or if you cleverly use a string to do something similar. Ah, so it is possible, I will study in this direction. Let the record show I tried to save honkytonk from wasting time.
|
|
|
Post by tsh73 on May 14, 2020 9:09:13 GMT
You can if you are willing to use arrays to manage state. Or if you cleverly use a string to do something similar. Ah, so it is possible, I will study in this direction. It *could* lead to better understanding how recursion works, but in all other aspects it would be like buying a bus ticket and refuse to ride.(IMHO)
|
|
|
Post by B+ on May 14, 2020 15:33:40 GMT
Ah, so it is possible, I will study in this direction. It *could* lead to better understanding how recursion works, but in all other aspects it would be like buying a bus ticket and refuse to ride.(IMHO) For a better understanding of how recursion works, first secure a solid understanding of how a procedure (SUB or FUNCTION) works. You have to have a bus built before you can ride it.
|
|
|
Post by honkytonk on May 15, 2020 10:35:03 GMT
The goal is to understand how the magic of self-calling subs works. And why we cannot go to a gosub when we are in a sub
|
|
|
Post by Rod on May 15, 2020 16:06:53 GMT
The solution is very easy. Step one free your mind. Step two never use gosub again until you understand subs and functions.
You will find it much easier than you think to code like this.
|
|
|
Post by honkytonk on May 15, 2020 22:18:38 GMT
The solution is very easy. Step one free your mind. Step two never use gosub again until you understand subs and functions. You will find it much easier than you think to code like this. I want to understand how and why works what I am going to use before I use it; so i will try to understand
|
|
|
Post by B+ on May 15, 2020 23:05:26 GMT
To further understanding the difference between a SUB and a GOSUB:
for x = 1 to 10 gosub [printX] call printX print "The main module says x = ";x print next end
[printX] 'GOSUB from main module variables have same scope as the main module. print "GOSUB [printX] says x = ";x return
sub printX 'the variable x in this SUB is completely independent of x in main module or GOSUB print "The SUB printX says x = ";x end sub
|
|