In the examples in the previous section, notice that each time the functions get called recursively, the argument gets smaller by one, so eventually it gets to zero. When the argument is zero, the function returns immediately, without making any recursive calls. This caseβwhen the function completes without making a recursive callβis called the base case.
If a recursion never reaches a base case, it will go on making recursive calls forever and the program will never terminate. This is known as infinite recursion, and it is generally not considered a good idea.
In most programming environments, a program with an infinite recursion will not really run forever. Eventually, something will break and the program will report an error.
You should write a small program that recurses forever and run it to see what happens. Below is an example. The function adds to the number n instead of subtracting, which means it is always larger than 0. Therefore, the function executes βforever.β If you tried to run the program, it would run until it exhausted the available memory for its call stack and crashed. (If you run a infinitely recursive program in an Activecode in this book, it will be terminated automatically after a few seconds and you will get an error message.)