Optimize loop

This is a slightly more optimal way to loop, since it avoids looking up the .length property on every iteration.