General question

  • Thread starter Thread starter David
  • Start date Start date
D

David

Can anyone tell me the use of calling a sub inside itself.... please
Just some exemple to understand the uses
Thx for your help!
 
Hi David
one reason is the use for recursive algorithms. e.g. calculation of the
factorial (e.g. 5! =1*2*3*4*5):
Function fact(i as integer) as long
If i = 0 then
fact = 1
else
fact = i*fact(i-1)
end if
end function
Of course you can achieve this without recursion but this way its
'easier' to read.

you may have a look at the following site:
http://cse.unl.edu/~dsadofs/RecursionTutorial/index.php?s=algorithms
for more information (or just do a google search for 'recursive
algorithms')

HTH
Frank
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top