Even better is to use tail calls instead of loops and eliminate mutable variables entirely.