A function that calls itself repeatedly is known as recursive function and this technique is called recursion. When you create a recursive function, you must create a condition so that the function does not call itself indefinitely.
You can see in the above diagram that recursion is executed indefinitely. To get rid of these type of indefinite recursive, we use control statements.
Example: Swift 4 Program to print N positive numbers
Countdown: 6 5 4 3 2 1 0
You can see in the above program that the statement print("Countdown:") gives the output and the statement countDownToZero(num:3) calls the function that takes a parameter Integer.
The statement inside the function countDownToZero() executes and if the condition num > 0 is fulfilled, the function countDownToZero() is called again as countDownToZero(num: num - 1).
When the condition is not fulfilled, the function call is not done and the recursion stops.
Example2: Swift 4 program to find factorial of a number
The factorial of 6 is 720