Add asserts to the end of the function too.
Loop's can live in the middle, take as much I/O and compute out of the loop as you can :)