Quick question about 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: Quick question about foreach (
/showthread.php?tid=604550)
Quick question about foreach -
Kimble - 06.04.2016
Here you go:
Код:
foreach(new i : Player)
{
if(IsPlayerConnected(i)) // Is this necessary?
{
// Do stuff.
}
}
Thank you.
Re: Quick question about foreach -
AndySedeyn - 06.04.2016
No. It handles that internally.
Read this if you're interested in reading a discussion about for vs foreach:
https://sampforum.blast.hk/showthread.php?tid=169782
Re: Quick question about foreach -
ikey07 - 06.04.2016
also you dont even need to use that new i : Player,
just use foreach(Player,i)
Re: Quick question about foreach -
AndySedeyn - 06.04.2016
Quote:
Originally Posted by ikey07
just use foreach(Player,i)
|
That syntax is deprecated.
Re: Quick question about foreach -
PT - 06.04.2016
PHP код:
foreach(new i : Player)
{
// Do stuff.
}
foreach already checks if is online, because he only will be on "iter" if is online.