SOURCE

//利用3种循环来计算1+2+3+…+100的值
//1 .for循环
function sum_all() {
    var result = 0;
    for (var i = 0; i <= 100; i++) {
        result += i;
    }
    return result
}

var s = sum_all();

console.log(s);

//2. while()循环
function sum_all2() {
    var result2 = 0;
    var i = 0;
    while (i < 100) {
        i++;
        result2 += i;
    }
    return result2
}

console.log(sum_all2());


//3.do-while语句

function sum_all3() {
    var result3 = 0;
    var i = 0;
    do {
        i++;
        result3 += i;
    }
    while (i < 100);

    return result3
}

console.log(sum_all3())
console 命令行工具 X clear

                    
>
console