Three patterns you'll use forever
Most loops in real programs do one of three jobs: add things up, count things, or find the biggest (or smallest). Learn these patterns and you'll recognise them everywhere.
Pattern 1: the running total
Start a total at 0, then add to it each time around. The variable that collects the result is called an accumulator.
let total = 0;
for (let i = 1; i <= 5; i++) {
total += i;
}
console.log(total);