Recursion in computer science
According to wikipedia recursion is a method of solving a computational problem where the solution depends on solutions to smaller instances of the same problem.
Program or function that calls its self, easy right? lets see an example.
A factorial is the sum of every natural number below the base of the factorial. You can make a function that calls its self repeatedly, till reaching one, then start returning to every superior layer the sum of every number below the number on wich we are on.
Recursion is :
-A method of calling a function within the same function.
-Slower execution than using a loop
-Stack is used to store the local variables when a function is called.
A recursion must have a base case, must call itself, recursively and must change it´s self and move towards the base case.
It´s true that a loop statement can solve most (if not every) problems a recursion can, but its good to have in mind that both are valid approaches to use.
Thanks for reading!