Answers for "9.5. The Accumulator Pattern¶"

0

9.5. The Accumulator Pattern¶

let n = 6;
let total = 0;

for (let i = 1; i <= n; i++) {
   total += i;
}

console.log(total);

/*The variable total is initialized to 0. The loop executes once each for
  the values of i from 1 to 6. Each time the loop body executes, the 
next value of i is added to total.*/
Posted by: Guest on June-17-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language