C - 循环无限

时间:2016-10-27 15:09:22

标签: c

此代码中的if (doubles === 3) { alert("You got three pairs of doubles!!! It only took you " +count+ " rolls to get it! Now, go directly to jail, do not pass go, and do not collect $200"); if (lowest > count){ lowest = count document.getElementById('lowestLine').innerHTML = count; } doubles = 0; count = 0; } 循环永远不会完成并陷入无限循环但我无法弄清楚原因。在for循环中进行赋值时,我尝试使用临时变量代替i,但这也不起作用。

指针指向大小为for的数组,其余代码运行正常,而10循环不存在。此外,计算机只猜测for。我猜这只是我的一个愚蠢的错误,但我无法弄明白。

编辑:只需提取帖子中的所有代码

0

2 个答案:

答案 0 :(得分:1)

你的问题不是for循环,而是playGame函数中的do-while循环。 while条件需要更改为

while ((*(human+computerShot == 1) || (*(human+computerShot) == 3));

因为你想要在等于1或3(已分别击中或错过)时重做镜头

答案 1 :(得分:0)

在循环中的某个点,指针将i的值更改为零。您的代码也将pos1和pos2指定为零。