-
window.onload=function(){
-
for (var i = 1; i <=5; i++) {
-
console.log(i*i+'for');
-
};
-
console.log(i*i+"for-out");
-
whiletest();
-
}
-
function whiletest(){
-
var i =1;
-
while(i<=5){
-
console.log(i*i+'while');
-
i++;
-
}
-
console.log(i*i+"while-out");
-
}
控制台结果:
-
1for
-
4for
-
9for
-
16for
-
25for
-
36for-out
-
1while
-
4while
-
9while
-
16while
-
25while
-
36while-out
之前一直没有注意,也怪自己学艺不精,i变量循环时,在满足循环条件后,还会再次累加一次,以便判断是否满足循环条件,这是的i已经变成6了。不满足跳出循环,可是i=6已经是事实!!
阅读(391) | 评论(0) | 转发(0) |