ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   General question (https://www.excelbanter.com/excel-programming/290193-general-question.html)

David

General question
 
Can anyone tell me the use of calling a sub inside itself.... please
Just some exemple to understand the uses
Thx for your help!




Frank Kabel

General question
 
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/Recursio...p?s=algorithms
for more information (or just do a google search for 'recursive
algorithms')

HTH
Frank



David wrote:
Can anyone tell me the use of calling a sub inside itself.... please
Just some exemple to understand the uses
Thx for your help!





All times are GMT +1. The time now is 05:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com