Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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.*/
Source by education.launchcode.org #
 
PREVIOUS NEXT
Tagged: #The #Accumulator
ADD COMMENT
Topic
Name
1+7 =