Recursion does work (in DBPro anyway) and your snippet is working to a point, added something to see what's going on in there:
sync rate 10
F( 1, 10)
wait key
function F ( x, y )
if x >= y
print "X: ";x;" Y: ";y
else
mid = (y-x)/2
F(x, mid)
F(mid,y)
endif
` added so we can see whats going on
sync
do
if spacekey() then exit : ` exit loop and continue
if escapekey() then end : ` exit program
loop
endfunction
...but your snippet was stuck in a loop and very quickly ran out of stack space, a common problem if a function calls it'self too many times.
Because functions can't return multiple return values (yet!) I find recursion works best with global variables.
` recursion example showing 3-1 times table
sync rate 10
global num
global multi
multi = 3
multiRec()
wait key : end
function multiRec()
if multi > 0
num = 10
numRec()
multi = multi - 1
multiRec()
endif
endfunction
function numRec()
if num > 0
ans = num * multi
print str$(num) + " x " +str$(multi) + " = " + str$(ans)
sync
num = num - 1
numRec()
endif
endfunction
The downside of recursion is it can be very hard to follow what's going on, making debugging a pain in the... I'll let you finish that sentence
Hope this helps
Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.