And then there were three.
The rules of recursion are so succinctly stated here. From /r/learnpython:
There are 3 rules for recursion:
- A recursive algorithm must have a base case.
- A recursive algorithm must change its state and move toward the base case.
- A recursive algorithm must call itself, recursively.
A base case just means that it has an end point, something to stop it looping infinitely, such as when a particular variable reaches zero.
Changing its state means that through each iteration it gets closer to this variable.
Calling itself just means that you call the function that you’re currently in with this new data to pass in.