Wednesday, February 8, 2012

Recursion

Here is an interesting fact
When using recursion you must use the pre ++ operator instead of the post ++ operator

function doThis(X)
{
if( x< 10)
doThis(++X);
else
return X;
}

WHY? Well otherwise the recursion call only takes the value and not the incremented value.

FYI
x + 1; does seem to work fine