gpt4 book ai didi

Javascript++ -- 帮助

转载 作者:行者123 更新时间:2023-11-30 16:07:08 29 4
gpt4 key购买 nike

为什么这个脚本的输出是 5 而不是 8 ?

我认为 -- 意味着 -1 两次。

<html>
<body>
<script>
var x = 0;

var y = 10;

while ( x < y ){

x++;

y-- ;

}

document.write(y);
</script>
</body>
</html>

最佳答案

第一次迭代:

x = 0
y = 10

第二次迭代:

x = 1
y = 9

第三次迭代:

x = 2
y = 8

x什么时候不会小于y?当 x 等于或大于 y 时:

x = 5
y = 5

关于Javascript++ -- 帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36866764/

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