The "Break" Statement

This section explains the various uses for the "break" statement.

The "break" is used to end prematurely a for, repeat, while, do... until loop of some kind, or to tell a switch statement to end at that point, or to prematurely end a with function. Below you can see a few examples of how this can be used, and its syntax is simply:

GML Code Example

break;



"break" in a for loop:

GML Code Example

{
 var i;
 for (i = 0; i < 10; i += 1)
    {
    if array[i] = 234 break;
    }
 num = i;
 }
 


"break" in a repeat loop:

GML Code Example

{
 var i, temp;
 i = 0;
 temp = 0;
 repeat (10)
    {
    temp += array[i];
    if temp > max_total break else i += 1;
    }
 }
 


"break" in a while loop:

GML Code Example

{
 var i;
 i = 0;
 while (!place_free(x, y))
    {
    x = random(room_width);
    y = random(room_height);
    if i > 50 break else i+=1;
    }
 }
 


"break" when using with:

GML Code Example

{
 var count = 0;
 with (obj_Enemy)
    {
    count++;
    if count > 10 break;
    hp = 100;
    }
 }
 





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