Write a 0-10000 cumulative js code

Here is a code to implement the accumulation of 0 to 10000 in JavaScript:

let sum = 0;
for (let i = 0; i <= 10000; i++) {
  sum += i;
}
console.log(sum);

A for loop is used in the code, starting from 0 and looping to 10000. Each time through the loop, the value of i is added to the variable sum. Finally, use console.logthe function to output the accumulated result.

Guess you like

Origin blog.csdn.net/weixin_35755562/article/details/129532868