Looping - Question - 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: Looping - Question (
/showthread.php?tid=589806)
Looping - Question -
rappy93 - 22.09.2015
Hey guys,
I have decided to start optimizing my script and I wanted to start with player loops.
Which one of these is faster?
1. Using foreach? If yes, what is the best syntax? If you could provide a basic example it would be awesome!
2. Using
for like this?
pawn Код:
for(new i; i <= GetPlayerPoolSize(); i++)
{
//code
}
Really looking forward to your answers.
Re: Looping - Question -
Jastak - 22.09.2015
I am not sure which is the fastest, But I help you in the sintexis of the foreach.
Код:
// This is the basic use.
foreach(Player, i)
"Player" is the keyword for the loop and "i" is the variable
Re: Looping - Question -
J0sh... - 22.09.2015
Quote:
Originally Posted by Jastak
I am not sure which is the fastest, But I help you in the sintexis of the foreach.
Код:
// This is the basic use.
foreach(Player, i)
"Player" is the keyword for the loop and "i" is the variable
|
Nope, latest versions of foreach use foreach(new i : Player)
OT: Foreach is the fastest.
Re: Looping - Question -
Jastak - 22.09.2015
Quote:
Originally Posted by Jamester
Nope, latest versions of foreach use foreach(new i : Player)
OT: Foreach is the fastest.
|
Oh, Tanks for the information.
Re: Looping - Question -
rappy93 - 22.09.2015
Quote:
Originally Posted by Jamester
Nope, latest versions of foreach use foreach(new i : Player)
OT: Foreach is the fastest.
|
Thats it! I knew the old way to use foreach but I couldn't find the new one, the one you mentioned above.
I'll change my player loops to this one then, thank you guys!
PS: What version of foreach works with this syntax?
Re: Looping - Question -
Sew_Sumi - 22.09.2015
Quote:
Originally Posted by rappy93
PS: What version of foreach works with this syntax?
|
You should be using the latest version anyway.
Re: Looping - Question -
rappy93 - 22.09.2015
Is this the latest version?
https://sampforum.blast.hk/showthread.php?tid=570868
Re: Looping - Question -
Sew_Sumi - 22.09.2015
Yep.
Re: Looping - Question -
Uberanwar - 23.09.2015
Quote:
Originally Posted by Jamester
Nope, latest versions of foreach use foreach(new i : Player)
OT: Foreach is the fastest.
|
What, really? I thought it's the same with (Player, i). Is there actually any difference in form of performance?
Re: Looping - Question -
J0sh... - 23.09.2015
Quote:
Originally Posted by Uberanwar
What, really? I thought it's the same with (Player, i). Is there actually any difference in form of performance?
|
I don't think there is, but on the newer versions of foreach it will display warnings on your foreach loops telling you it's the old foreach syntax.