SA-MP Forums Archive
Break Statement - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Break Statement (/showthread.php?tid=392611)



Break Statement - Abreezy - 15.11.2012

Could someone explain how to use the break statement?

I tried it in this way:

pawn Код:
for (id = 0; id < 50; id ++)
    {
        if (SOMETHING[id] == 1)
        {
            break;
        }
        //do something with only that one id which break was used on
    }
But it still used all 50 ids for what I wanted it to do. I want it to find the first thing with that == 1 then use that id for something else, hopefully someone could explain how break; works in loops, thanks!


Re: Break Statement - Black Wolf - 15.11.2012

BREAK will get you out of the loop.


Re: Break Statement - Abreezy - 15.11.2012

I understand that, I want to know how to grab only a single ID from the loop as the break goes into place.


Re: Break Statement - ReneG - 15.11.2012

break; just jumps out of a loop
pawn Код:
new id;

for(new i=0; i<10; i++) {
    if(Something[i] == 1) {
        id = i;
        break; // calling break; won't stop the function
    }
}
// the code will just jump to here.



Re: Break Statement - Abreezy - 15.11.2012

Thanks, you're a life savior.