gpt4 book ai didi

JavaScript,For 循环 : returned 'i' value is different from that is stored

转载 作者:行者123 更新时间:2023-11-28 11:16:05 24 4
gpt4 key购买 nike

在此循环中,alert(i) 警报 12,firebug 显示 10 作为最终结果。

 for(var i=0;i<=10;i=i+2){
document.write=i;
}

alert(i);

最佳答案

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

关于JavaScript,For 循环 : returned 'i' value is different from that is stored,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29939266/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com