The "Repeat" Statement

This section explains how to use "repeat".

A "repeat" statement has the form

GML Code Example

repeat (<expression>) <statement>


The statement is repeated the number of times indicated by the rounded value of the expression. For example, the following program creates five balls at random positions.

GML Code Example

{
 repeat (5) instance_create(random(400), random(400), obj_ball);
 }
 


This can be very useful to avoid typing out the same code multiple times, or for using arrays, or for counting through a number of operations etc... For example:

GML Code Example

{
 var i, total;
 i = 0;
 total = 0;
 repeat (10)
    {
    total += array[i];
    i += 1
    }
 draw_text(32, 32, total);
 }
 





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