am *_*ath 0 javascript alert for-loop
在该循环中,alert(i)警报12和firebug显示10作为最终结果.
for(var i=0;i<=10;i=i+2){
document.write=i;
}
alert(i);
Run Code Online (Sandbox Code Playgroud)
i在每次循环迭代后增加.当条件失败时<= 10,循环中断:
0 => loop gets executed, i incremented with 2
2 => loop gets executed, i incremented with 2
4 => loop gets executed, i incremented with 2
6 => loop gets executed, i incremented with 2
8 => loop gets executed, i incremented with 2
10 => loop gets executed, i incremented with 2
12 => loop breaks => i remains at 12
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
63 次 |
| 最近记录: |