While

From Game Editor

Jump to: navigation, search

While is almost the same as if, but while loops the code after the expression as long as the given expression is true.

Example:

while(x > 0) x -= 1;

This code just moves the actor to the center. In this case you could also use "x = 0". If you would do it with the keyword if, it would move to the left only one pixel.

WARNING: Be careful using loops. You can make infinite loops easyly. Here is an example:

while(x > 0) x += 1;

If x is greater than 0, it can't get lower than or equal to 0, because it grows in the inverted direction. Surely this one would end at a large value of x, when the maximum is reached.