Looping
#1

I have a question that blown my mind, what is the good looping code? Because i see a lot of them...
The foreach? This:
Code:
for(new i=0; i <= GetPlayerPoolSize(); i++)
or:
Code:
for(new i = GetPlayerPoolSize(); i > -1; i--)
What is the good and optimized?
Reply
#2

You could just save the return value of GetPlayerPoolSize in a global variable every time a player connects/disconnects. Given that you don't know the complexity of GetPlayerPoolSize, you shouldn't make assumptions about it without testing.

The best way to figure whether or not something is efficient, you should just test it yourself.
Reply
#3

You can use the magic --> operator.

pawn Code:
new i = GetPlayerPoolSize() - 1;

while (i --> 0) {
// code..
}
Reply
#4

Don't complicate your life, there's no difference in a single loop as such (nanoseconds, nothing you should be worried about).

pawn Code:
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i ++)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)