SA-MP Forums Archive
how to use foreach - 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: how to use foreach (/showthread.php?tid=660720)



how to use foreach - ChrisPa - 11.11.2018

I understand that it is to optimize the server and avoid the use of for but I do not understand its operation try to read this but I still do not understand.
https://sampforum.blast.hk/showthread.php?tid=588526
please explain how it is used.



Re: how to use foreach - lollypap54 - 11.11.2018

You write:
Код:
foreach(new i : Player)
{
    //Code
}
Instead of:
Код:
for(new i; i < MAX_PLAYERS; i++)
{
    if(IsPlayerConnected(i))
    {
        //Code
    }
}
Also if you want to loop all existing vehicles you use Vehicle instead of Player.
That's all you need to know.