What is an 'Accumulator' pattern?

Asked by emeka_nwankwo · 6 months ago

1 Answer

32
amorebise · 6 months ago Top Answer

This is a common trick where you use a variable to keep track of a total inside a loop. Imagine starting with 0 Naira and adding 100 Naira every time you complete a chore.

You say total = total + 100 inside the loop. By the end, the 'total' variable has accumulated all the values. It’s how we do sums in coding.

Log in to add a comment.