Recursion
esse quam videri
Definition
Relevance
Example
Below is an example of a recursive function that will take a number and multiply it by two. The second argument is an "exit condition" that is used to stop the function from repeating.
void doubleNumber(int targetNumber, int minimumTarget)
{
targetNumber *= 2; // This will set the variable to itself * 2
if(targetNumber < minimumTarget) // Check if the desired minimum has been reached. If no, execute again!
{
doubleNumber(targetNumber, minimumTarget); // This function calls itself (That's the recursive part!)
}
// If the above conditional statement doesn't execute, the recursion will end.
}