Cache the length outside the loop.