It also gets rid of the duplication of code between the debug output and the actual return value calculation by folding both into the same loop.
It also gets rid of the duplication of code between the debug output and the actual return value calculation by folding both into the same loop.