I've tested the function and it's working, the value of i is being decremented at the end of while statement. But I can write the function to be more readable, in that point you're right.