A function that calls itself is known as a recursive function. And, this technique is known as recursion. While creating a recursive function, you must create a condition so that the function does not call itself indefinitely (infinitely).
In the article Swift functions, we created a function using func keyword. However, there is another special type of function in Swift, known as closures that can be defined without using keyword func and a function name.
Like functions, closures can accept parameters and return values. It also contains a set of statements which executes after you call it and can be assigned to a variable/constant as functions.
Two or more functions having same name but different argument(s) are known as overloaded functions.
Why do we need function overloading?
Imagine you are developing a shooter game where the player can attack its enemies using a knife, a blade and a gun. Your solution for the attack functionality might be defining the actions into functions as: