Coffee Room

Discuss anything here - everything that you wish to discuss with fellow engineers.

12915 Members

Join this group to post and comment.

# How to stop recursion function?

Can you plzz say me how to stop the recursion function

Generally the recursion function will quit based on the condition stated in the function or using a break statement or a return functionPreethi RamanCan you plzz say me how to stop the recursion function

can u pls tell me the exact problem wher u want to break the function so that i can be more clearPreethi RamanCan you plzz say me how to stop the recursion function

Recursive functions always contain 2 parts.First that indicates action to be done by this call and second is the one that recursively calls the function again.We may specify condition that is to be satisfied for calling recursively or may also specify the condition of terminating the recursion process.

For eg: In factorial we continously call until the argument passed is 1 and when argument is 1 we simply return 1 so stop the recursion

For eg: In factorial we continously call until the argument passed is 1 and when argument is 1 we simply return 1 so stop the recursion

Thanks a lot for your answer..and

Its clear that we can terminate the recursive function either by a break,goto,and return functions..

**also does the recursion function forms****an infinite loop???**Its clear that we can terminate the recursive function either by a break,goto,and return functions..

break and goto are used to terminate loop.

If you don't specify any statement to terminate,it will form infinite loop.Preethi Ramandoes the recursion function forms

an infinite loop???

e.g

void func() { func(); }

i think u r not knowing correct concept of recursionPreethi RamanCan you plzz say me how to stop the recursion function

Given here in pseudocode:

function factorial(n)

{

if (n<=1)

return 1;

else

return n * factorial(n-1);

}

{

if (n<=1)

return 1;

else

return n * factorial(n-1);

}

recursion function have a base condition ....

every time the function is called ... the value moves closer to he base condition....

every time the function is called ... the value moves closer to he base condition....

Please try :

publicstaticvoidMain(string[]args)

{

tampil(10);

}

privatestaticvoidtampil(inti)

{

Console.WriteLine("Halo"+i.ToString());

if(i>0)

tampil(i-1);

}

publicstaticvoidMain(string[]args)

{

tampil(10);

}

privatestaticvoidtampil(inti)

{

Console.WriteLine("Halo"+i.ToString());

if(i>0)

tampil(i-1);

}