When does recursion stop

Viewed 106

To stop the recursion we must provide an base. Apart from providing the base, when does a recursion stops. Does it stops when it stops calling itself again?.

def func(x):
    n=[]
    for i in n:
        func(x)

Here, does it call the function or does nothing. Does recursion stop at scenario like this and starts backtracking?

2 Answers

The 4th line in your code does not get executed as the list n contains no elements. Hence funcgets terminated without any recursion.

Since n is empty, the for loop will do nothing, and func will just terminate without performing any recursion.

Related