SOURCE

//利用3种循环来计算1+2+3+…+100的值。

//for循环
var sum=0;
for(j=100;j>0;j--){
    sum=sum+j;
}
document.write("for循环:"+sum);
document.write("<br/>")

//while循环
var n=1;
var sum1=0;
while(n<=100){
    sum1=sum1+n;
    n++;
}
document.write("while循环:"+sum1);
document.write("<br/>")

//do...while循环
var m=1;
var sum2=0;
do{
    sum2=sum2+m;
    m++;

}while(m<=100);
document.write("do...while循环:"+sum2);
console 命令行工具 X clear

                    
>
console