Break Statement
#1

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!
Reply
#2

BREAK will get you out of the loop.
Reply
#3

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

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.
Reply
#5

Thanks, you're a life savior.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)