Recursive Function
The Function which Calles Itself is known as Recursive Function.
Example:
If I ask you to print numbers from 1 to 10 without using loop.
Can you do??? No... So, Let me introduce you to the concept of Recursion.
Syntax
Here,
Once you call the Function recursion then the statements inside the function will run. i.e. recusion(); will be called again.
Example
Here,
We have declared a Global Scope Variable no
Then Function called printNo();
Let's Understand the Function printNo();
At First, no is printed in Console.
no+=1 i.e. no = no + 1
Then we have used, If Condition
if no is less than 10 then function will be called again.
otherwise, function will be terminated.
Note:
You Should be Very Careful while using the Recursive Function. Because Many Beginners When Try to do Looping using Recursive Function, They usually Forget to Put Condition to Stop the Loop, resulting in Infinite Loop and Crashing of the Program.
So, Don't Forget to Put Condition to Stop the Loop, you can use if condition to stop the Iteration of The Loop.