A recursive function calls itself to solve smaller versions of a problem. Every recursive function needs a base case to stop:
func factorial(n int) int {
if n <= 1 {
return 1 // base case
}
return n * factorial(n-1) // recursive case
}
Without a base case, the function would call itself forever and crash. The base case provides a stopping point. The recursive case breaks the problem into a smaller piece.