Help in recursion function

I am trying to create a recursion function using iterations , in a brief the function checks if the iteration is equal to zero , if it does the function stops , if it doesn’t the function starts and at the end it returns itself and it returns iterations -1 to determine the recursion steps , like the following ;

def Function( inputList , iterations):
NewList =
if iterations == 0 :
return “finished”
else :
process (inputList)
etc…
NewList.append(process result)
return def Function( NewList , iterations-1)

OUT = Function( input , iterations)

the problem is when ever i run the script , dynamo gives the result “finished” , means that the iteration is 0
any help plz lineloop2.py (2.0 KB)

What do you want it to return? Because you only have it returning “finished” when iterations == 0

1 Like

Agree with @kennyb6 here. In the last iteration, you should return something like :

if iterations == 0:
    return polygon

That way you are sure that the last polygon you calculated is your the result returned by your function.

2 Likes

Thank you very much for your reply , it worked , I am used to script in Rhino which runs the function then return the polygon and the “finished” results , it confused me but now it worked thanx again

Thank you very much for your reply , it worked , I am used to script in Rhino which runs the function then returns both the polygon and the “finished” results , it confused me but now it worked thanx again

Glad it worked out for you. Can you mark @mellouze’s post as the solution so if anyone has the same problem in the future, they can find the answer easily?