Base Case

A base case is the condition in a recursive function that stops the recursion. Without it, the function would call itself forever and crash.

General Programming

Every recursive function needs at least one base case (the simplest input that returns a direct answer) and a recursive case that moves toward it.

Examples

Python

def countdown(n):
    if n == 0:        # base case
        print("Done")
        return
    print(n)
    countdown(n - 1)  # recursive case

countdown(3)

Output:

3
2
1
Done

See also

Back to the Dictionary