Calculate the array length outside of the loop