Optimized For Loop

By storing array.length outside of the loop in a variable, the
array.length method is called only once.