[Question] What's better?
#1

Hi, this question is about "if" statements in "for" loops. So I've seen people doing it these ways:

Way 1
pawn Код:
for(new i=0; i<MAX_PLAYERS; i++)
     if(IsPlayerConnected(i))
          Kick(i);
Way 2
pawn Код:
for(new i=0; i<MAX_PLAYERS; i++)
     if(!IsPlayerConencted(i))
          continue;

     Kick(i);
So my question is, which way is better?
Reply
#2

pawn Код:
for( new slots = GetMaxPlayers( ), i; i < slots; i++ )
{
    if ( !IsPlayerConnected( i ) ) continue;
   
    Kick( i );
}
Код:
This forum requires that you wait 120 seconds between posts.
Mneah, that's not fair....
Reply
#3

Better for what? There is no speed difference...

I suggest you to use foreach.
Reply
#4

Quote:
Originally Posted by Pooh7
Посмотреть сообщение
Better for what? There is no speed difference...

I suggest you to use foreach.
Yes it is my friend, what I've posted is the fastest plain player-loop, foreach is faster than that, you're right, but this is the normal way...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)