I am tracing the following recursive function but i am going into an infinite loop. However when i run the function as a java program its generating an answer. The function is:

static int fun(int i)

{

boolean res=false;

if(i%2==1)

res=true;

else

res=false;

if ( res )

return (i++);

else

return fun(fun( i - 1 ));

}

It has to be invoked using:

fun(4):

My steps of tracing are as follows:

fun(4)

= fun(fun(3))

= fun(4)

= fun(fun(3))

= fun(4)

Can somebody please tell me where i am making the mistake??

Zulfi.