For loop optimization

For loops were not caching the length of the loop