Reduced computations in loop