[Question] Return in loop
#1

What happens if I return a value in a loop ? The loop will be ended and script stopped ? Or just the script stopped after the loop is finished ?
Reply
#2

It will stop everything. The callback will no longer carry on.

pawn Код:
public OnPlayerSpawn(playerid)
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(i == 5) return 1;
    }
    print("THIS WILL NEVER BE CALLED.");
    return 1;
}
break; will stop the loop but still continue with the code below it, and continue; will skip one iteration (call) of the loop and move on to the next interation.
Reply
#3

Quote:
Originally Posted by MP2
Посмотреть сообщение
It will stop everything. The callback will no longer carry on.

pawn Код:
public OnPlayerSpawn(playerid)
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(i == 5) return 1;
    }
    print("THIS WILL NEVER BE CALLED.");
    return 1;
}
break; will stop the loop but still continue with the code below it, and continue; will skip one iteration (call) of the loop and move on to the next interation.
Thanks. I already knew what break; and continue; do.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)