Watch total grow
total (accumulator)
0
0 + 1 + 2 + …
1total = 0
2for i in range(1, n + 1):
3total += i
Start with total = 0. Each loop adds the next i. This is how apps sum cart prices, steps, or scores.
Start at 0. Each loop adds the next number into total.
This loop keeps adding the next number into a running total. It turns many small values into one final sum.
Used in cart totals, score totals, attendance totals, step counters, and report generation where data is accumulated over time.
You drop ₹1, then ₹2, then ₹3 coins. After each drop you update the running total. For n=5: 1+2+3+4+5 = 15.