• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Help me to break the loop after condition approval.

E

Edwin

Guest
Hey!
I already posted many topics where I asking about for loops because I'm very dumb at programming. I regret this.

Create Event:

Code:
array[0] = 0;
array[1] = 0;
array[2] = 0;
Press any key Event:
Code:
for (i=0; i < array_length_1d(array); i += 1) {
    if (array[i] == 0) {
        array[i] += 1;
    }
}
Goal:
I want to break the loop if it already found the array that equals 0, but I have no idea how to make it.
 

Rob

Member
Code:
for (i=0; i < array_length_1d(array); i += 1) {
    if (array[i] == 0) {
       //add code here if you want something to happen when you find "0"
       break;
    }
}
Only a small change needed.

You already have the line

Code:
 if (array[i] == 0) {
If you want something to happen when you found 0 add the code just above the break;

If you're not familiar with "break" then check it out in the manual.
 
E

Edwin

Guest
Code:
for (i=0; i < array_length_1d(array); i += 1) {
    if (array[i] == 0) {
       //add code here if you want something to happen when you find "0"
       break;
    }
}
Only a small change needed.

You already have the line

Code:
 if (array[i] == 0) {
If you want something to happen when you found 0 add the code just above the break;

If you're not familiar with "break" then check it out in the manual.
Oh, thanks! I am so dumb =D. I'm familiar with break and using it in switch statement every time but it looks like I am very tired or something and need to rest right now XD.
 

Rob

Member
Oh, thanks! I am so dumb =D. I'm familiar with break and using it in switch statement every time but it looks like I am very tired or something and need to rest right now XD.
My best bugs are made when I'm tired lol ;)
 
Top