REAL RECURSIVITY (working example)

by Lisztfr (no login)

 

Sometimes my recursivity examples here was fake, just another way to loop : decreasing a variable was the only thing the call-it-self did.

Now, recursif means not only change a variable but also change the data segment on which it applies, and treat all of these subsequent segments...

So inside the SUB, the SUB needs to call itself more than one time, because that IS recursivity. Else it is a LOOP.

EXAMPLE : each time the following routine calls itself, z% increases by 1, so the routine was called 16 times (for n = 4), 2 ^ 4



======================================

DECLARE SUB ADD (n)
COMMON SHARED z%

n = 4
z% = 1

CALL ADD(n)

PRINT z%

END


SUB ADD (n)

IF n < 1 THEN EXIT SUB

z% = z% + 1

CALL ADD(n - 1)
CALL ADD(n - 1)

END SUB

Posted on Sep 23, 2010, 5:12 AM

Respond to this message   

Return to Index

Response TitleAuthor and Date
No stack space issue ... ! on Sep 23
* 3 ^ 4 ? not working...Lisztfr on Sep 23
 How to compute cubics with that method ? on Sep 23
 Fibonacci in a SUB... ! on Sep 23
 Recursive hellLisztfr on Sep 23
  More stuff on Sep 24

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement