Cache length of array in for loops