Page 1 of 1

Recursive Functions

Posted: Thu Jul 22, 2010 1:10 am
by everydayrun
i don't know it very well,only know it return itself.now,i want to know how to use it. and do a deeply understand on it. any tips would be appreciated.

Re: Recursive Functions

Posted: Fri Jul 23, 2010 1:45 am
by everydayrun
anyone helps?

Re: Recursive Functions

Posted: Fri Jul 23, 2010 2:30 am
by VladSun
Take a look at the recursive definitions of Fibonacci series or factorials for examples:
http://en.wikipedia.org/wiki/Fibonacci_number
http://en.wikipedia.org/wiki/Factorial

In general you need a structure like this:

Code: Select all

function recursive(args, ...)
{
    if (condition_to_stop_rescursion_is_true)
        return (result_to_return_on_recursion_stop);
    else
        return recursive(args_to_be_passed_on_recursive_call);
}