foreach(Player,i or for(new 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: foreach(Player,i or for(new loop (
/showthread.php?tid=462927)
foreach(Player,i or for(new loop -
Blackazur - 09.09.2013
What should i use for this? that with foreach or with a loop?
Код:
foreach(Player,i)
{
Delete3DTextLabel(spawnprotection[i]);
}
for(new i=0;i<MAX_PLAYERS;i++)
{
Delete3DTextLabel(spawnprotection[i]);
}
Re: foreach(Player,i or for(new loop -
Dragonsaurus - 09.09.2013
They are both the same, but I think foreach is more faster.
Re: foreach(Player,i or for(new loop -
Tamer - 09.09.2013
Always use foreach
Re: foreach(Player,i or for(new loop -
Threshold - 09.09.2013
foreach was created for a reason, one of the reasons if because it was better and more efficient than using for( loops. So yes, in this instance, you should be using foreach.
Re: foreach(Player,i or for(new loop -
Weponz - 09.09.2013
foreach is
faster as it loops through the online player count
only.
The default loop will loop through MAX_PLAYERS, regardless of how many players are online, meaning excess looping.
So, due to this fact may I suggest you use foreach.