Looping - Question
#1

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.
Reply
#2

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
Reply
#3

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.
Reply
#4

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.
Reply
#5

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?
Reply
#6

Quote:
Originally Posted by rappy93
Посмотреть сообщение
PS: What version of foreach works with this syntax?
You should be using the latest version anyway.
Reply
#7

Is this the latest version?

https://sampforum.blast.hk/showthread.php?tid=570868
Reply
#8

Yep.
Reply
#9

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?
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)