How to return a value from a void function and use it inside the void loop?

You have an endless loop when you call print() from the print() function. (It is called in the return statement)