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
 
Back
Top