SOURCE

//for循环
var result = 0;
for (var i = 0; i <= 100; i++) {
result += i;
}
document.write("for循环");
document.write("<br />");
document.write("1+2+3+…+100 = "+ result);
document.write("<br />");

//2. while()循环
var result2 = 0;
var i = 0;
while (i <= 99) {
i++;
}
document.write("while()循环");
document.write("<br />");
document.write("1+2+3+…+100 = "+result);
document.write("<br />");

//3.do...while循环
var n = 1;
        var sum = 0;
        do
        {
            sum += n;
            n++;
        }while (n <= 100);
document.write("do...while循环");
document.write("<br />");
document.write("1+2+3+…+100 = " + sum);

console 命令行工具 X clear

                    
>
console