The "While" Statement

This section deals with the "while" statement and its use

A "while" statement has the form

GML Code Example

while (<expression>) <statement>


As long as the expression is true, the statement (which can also be a code block) is executed. Be careful with your while loops! You can easily make infinite loops, in which case your game will hang and not react to any user input anymore. Below you can find an example of a typical way to use "while":

GML Code Example

{
 while (!place_free(x, y))
    {
    x = random(room_width);
    y = random(room_height);
    }
 }
 


The above program tries to place the current object at a free position (this is about the same as the action to move an object to a random position).





No Examples Submitted

Does this page need better examples? Be the first to Submit

No Edits Suggested

Is this page unclear or not descriptive enough? Suggest an edit to the page and with enough upvotes your changes will be made.

No Questions Have Been Ask

Do you have a question about this page? Ask it Here