The goal for this exercise is to understand how what recursion is, how it operates within the computer (at a mechanical level), and to use that knowledge to successfully predict what a function produces as output. The longer-term goal is to get you familiar enough with recursion that you can eventually write (and debug, using the skills you’re developing in this exercise) your own recursive code.
What you need to do for this exercise:
namespace RecursionExercises
{
class Class1
{
[STAThread]
static void Main(string[]
args)
{
PrintHelper ph = new PrintHelper();
Console.WriteLine( "End result: " + ph.foo(5));
}
}
class
PrintHelper
{
public int foo(int f)
{
if
(f >= 8)
return
f;
Console.WriteLine( "Handed " + f );
int i;
if(f % 2 == 0)
i = foo(f + 2);
else
i = foo(f + 1);
Console.Write( "the return value is: " + i);
return
i;
}
}
}