Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
recursive formula
#1
I'd like to write a recursive formula to understand this principle better. I want the function to print something each time it passes. I tried to write such a thing before, but it only returns something (a number, eg.) and does not print while 'busy".

Can someone give me an example?
Reply
#2
Here's a very, very simple example. This will probably get up into the thousands before the program stops with an out of stack space error:
[syntax="qbasic"]DEFINT A-Z

DIM SHARED RecursionNumber

RecursionNumber = 0

DoIt

END

SUB DoIt

RecursionNumber = RecursionNumber + 1

PRINT "This is recursion #"; RecursionNumber

DoIt

END SUB[/syntax]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)