Summing with an Accumulator
Two common loop tasks
There are two common tasks that use for loops:1. Summing
2. Counting
2. Counting
This set is about summing. Counting comes next, and the two share a shape you will start to recognise.
Summing values
Write a segment of code that solves the problem 1 + 2 + 3 + ... + 98 + 99 + 100.We need a variable that accumulates the sum at each iteration of the loop. This variable should be initialized to 0.