The accumulator pattern

To total, count or find the biggest of many values, set a variable before the loop and update it on every pass, so that when the loop ends the variable holds the answer.

From Introduction to Computer Science.