SA-MP Forums Archive
[Question] Return in loop - 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: [Question] Return in loop (/showthread.php?tid=334764)



[Question] Return in loop - IstuntmanI - 15.04.2012

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 ?


Re: [Question] Return in loop - MP2 - 15.04.2012

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.


Re: [Question] Return in loop - IstuntmanI - 15.04.2012

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.