Direct Vs. Indirect Recursion
This lesson goes over two different types of recursion: direct and indirect recursion.
Direct Recursion
Direct recursion occurs when a function calls itself.
This results in a one-step recursive call, meaning that the function makes a recursive call inside its own function body.
Syntax of Direct Recursion
def function1(p1, p2, ..., pn) :
# Some code here
function1(p1, p2, ..., pn)
# Some code here
Printing Natural Numbers from to Using Direct Recursion
Let’s take a look at an example of a function that prints natural numbers from to :
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.