🧮Base Case
Also known as Base Case (Recursion), Stopping Condition, Terminating Case
The simple case where a function that calls itself stops.
Think of it like
It is like the bottom step of a staircase. Once you reach it, you stop going down.
Example
A countdown function prints n, then calls itself with n minus 1. When n is 0, the base case prints Go! and stops.
Why it matters
Definition
Example code
python
def countdown(n):
if n == 0: # base case
print("Go!")
return
print(n)
countdown(n - 1)
countdown(3) # 3 2 1 Go!Common mistake
Key takeaways
- 1Answer at once. No more self-calls.
- 2Must be reached. Each call moves toward it.
- 3Stops the stack. Without it, the program crashes.