Structure of a Recursive Program
Learn about the basic structure of the recursive function.
Basic syntax
Let’s go over the basic syntax of the recursive function.
The recursive function consists of the following two parts:
-
if: represents the base case when the function should stop calling itself. It simply returns the result to the calling point.
-
else: represents the recursive case when the function calls itself repetitively until it reaches a base case.
Illustration
The recursive function keeps calling itself in a nested manner until it encounters a base condition. When the base condition is reached, it continues returning the value to the calling function until the original calling function is reached.
📝 The purpose of the main function is ...