Tuesday, 13 August 2013

Method and loops in C#

Method and loops in C#

I am new to methods and loops. If someone can explain why my code isnt
running properly , it would be appreciated.
1)the code first loops and writes 'Test' and the runs the second WriteLine
afterwards. Shouldn't it only WriteLine once since the method is being
called and terminated before the WriteLine?
2) The WriteLine is writing 50 - and not counting 20 + . Why is that?
Thank you.
The following is my code.
}
Count(20, 50);
Console.ReadKey(true);
}
static void Count(int first, int last)
{
if (first <= last)
{
Console.WriteLine("Test!");
Count(first + 1, last);
Console.WriteLine(first);
}
}

No comments:

Post a Comment