Is there a reason to not want to use a recursive function? There is performance boost from rewriting in loop form, but it is only important in tight loops, not in helper functions.

Anyway, it you want to do it only for some performance reasons, do __not__ do it before you have actually checked that it makes it faster.