Correct the loop termination condition. Try a more declarative expression of the sum as an exemplar.