对于循环不工作

ale*_*tti -4 java for-loop

我正在测试for循环,以便在屏幕上平滑移动对象.

int yPosLeft = 339;
int originalYPosLeft = yPosLeft;

for(yPosLeft < 30 + originalYPosLeft; yPosLeft++) {
// Changes the value in the statement
}
Run Code Online (Sandbox Code Playgroud)

然而,循环以某种方式使对象的y位置永远进入负数百万,并且几乎需要强制退出.有什么建议?

更新:我对此很愚蠢.为#BrainFart #Fixed道歉

Mic*_*rry 5

你的条件是:

yPosLeft < 30 + yPosLeft
Run Code Online (Sandbox Code Playgroud)

......永远都是真的.值始终小于30加上相同的值.

因此,循环将永远持续,你的对象的y位置将永远移动!(也就是说,直到它yPosLeft变得如此之大以至于溢出 - 但我严重怀疑这是所期望的行为.)