When using an accumulating variable there are three stages:
- Initialise
-
We declare our accumulator and set it to an initial values.
- Update
-
Inside the loop we update the accumulator - we take into account the
current data item.
- Output/use
-
After the loop our accumulator contains the required value. We use it
or output it.