recursive calls - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# recursive calls

Posts: 7Member
Hi;
Can someone tell me if on the net exists any site or tutorial that explains these recursive procedures or functions.
Thanks

• Posts: 117Member
: Hi;
: Can someone tell me if on the net exists any site or tutorial that explains these recursive procedures or functions.
: Thanks
:
hi recursive??
• Posts: 757Member
: Hi;
: Can someone tell me if on the net exists any site or tutorial that explains these recursive procedures or functions.
: Thanks

Recursive functions are pretty easy to understand, but very confusing to use. Basically, you make a procedure that calls itself. This is done to accomplish things that would otherwise take alot of coding.

An example of recursive procedure is a FILL procedure in graphics or an equation such as the "Towers of Hanoi" (complicated ancient Monk problem)

Here is a basic recursive function:

[code]
FUNCTION Recursion(X : Word) : Word;
Begin
If X < 10 Then
Recursion := Recursion(X+1);
WriteLn('Recursion Function #',X);
End;

Begin
Recursion(1);
End.
[/code]

If you were to run this, you would have the following steps taken:
[01] Recursion(1) is called
[02] X(=01) < 10 Then Recursion := Recursion(X+1) is called;
[03] X(=02) < 10 Then Recursion := Recursion(X+1) is called;
[...]
[08] X(=07) < 10 Then Recursion := Recursion(X+1) is called;
[09] X(=08) < 10 Then Recursion := Recursion(X+1) is called;
[10] X(=09) < 10 Then Recursion := Recursion(X+1) is called;
[11] X(=10) is not < 10, so WriteLn('Recursion Function #',X);
[13] X(=09)WriteLn('Recursion Function #',X);
[15] X(=08)WriteLn('Recursion Function #',X);
[...]
[27] X(=02)WriteLn('Recursion Function #',X);
[29] X(=01)WriteLn('Recursion Function #',X);
[30] Done!

[code]
Recursion Function #10
Recursion Function #9
Recursion Function #8
Recursion Function #7
Recursion Function #6
Recursion Function #5
Recursion Function #4
Recursion Function #3
Recursion Function #2
Recursion Function #1
[/code]

Hope this explains it a bit.
Phat Nat