I have the following code in c#
class Program
{
private static int WriteToConsole(int NumWrites)
{
int i = NumWrites;
while( i > 0)
{
Console.WriteLine("Loop {0}", i);
i = WriteToConsole( i – 1);
}
return NumWrites – 1;
}
static void Main()
{
WriteToConsole(3);
Console.ReadKey();
}
}
With the question "What does the console show after running this?"
The correct answer is 3 2 1 1
But I don't understand where the extra one is coming from in this loop. After the first loop that writes 1 to the console, doesn't returning NumWrites (Which is 1 at this point) minus 1 equal 0, making int i 0 and stop the loop before it can run again with 0? I know I'm missing a step but can really pin down where.