The "Repeat" Statement

This section explains how to use "repeat".

A "repeat" statement has the form

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.

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:

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

Back: GML Overview
Next: The "While" Statement
© Copyright YoYo Games Ltd. 2018 All Rights Reserved