There is no problem with the code, I just have a question about it. How come that one counts down from 10 to 0, but if you put the "cout" after the "if," it counts up from 0 to 10? Is it because the condition is stated before the variable? Any help would be appreciated.

05-09-2005

Stoned_Coder

10s a bit hard lets look at 3

heres your func swopped...

Code:

{
if ( x > 0 ) count ( x - 1 );
cout << x << endl;
}

now call with x=3

x is greater than 0 so count(2)
in count(2)
x is greater than 0 so count(1)
in count(1)
x is greater than 0 so count(0)
in count(0)
x is 0 so cout x
back in count(1)
cout x
back in count(2)
cout x
back int count(3)
cout x

so u see 0,1,2,3 is printed.

Now work that thru for the original and you will see why its forwards one way and back the other.