How can I return to loop from another function?