我的 for 循环正在下降并在 2 处停止,
for(int fadeValue = startingPoint ; fadeValue >= 0; fadeValue -=3)
//fade value stops at 2.
我希望它始终为 0(fadeValue
并不总是除以 3)。
我怎样才能改变它来做到这一点?
最佳答案
用途:
for(int fadeValue = startingPoint ; fadeValue >= 0;
fadeValue = (fadeValue==1 || fadeValue==2) ? 0 : fadeValue-3)
这确保了在 1 或 2 的迭代之后有最后一次迭代为 0,而不会使循环无限。
关于c - 一个简单的 C for 循环不会下降到 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27130904/