On Feb 2, 2006, at 10:55 AM, Chuck Pelto wrote:
Here is a very simple one:
Function PowerTo(x As Integer, n As Integer) As Integer
If (n <= 1) Then Return 1
Return x * PowerTo(x, n - 1)
End Function
So, by way of my described situation, what are X and N supposed to
be? Besides integers?
Is X the number of levels? Or is N? And which is the data?
X is the data and N is the number of levels. It is a hand-coded
power function, and not very fast, but used to illustrate the point.
For example if you call PowerTo(2, 4), the method is called 4 times
(once by you and three times recursively) and returns the value of
16. It continues to call deeper and deeper until (n = 1) and then it
starts backing out of the stack until it returns from the function
you initially called.
Google for "Recursion" as it is a very common topic for programming
lectures. And here is the Wikipedia link:
http://en.wikipedia.org/wiki/Recursion
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>