Document what is going on in this loop and why.