You are probably missing an exit condition. Show the codes you have.
In a nutshell:

if condition is met
return
else
call function again