Question about for loops
#1

Hello, While looking in some game modes, i saw this loop
pawn Код:
for(new i; i<MAX_PLAYERS; i++)
{
    if(IsPlayerConnected(i))
    {
        // do the stuff here.
    }
}
Question is, why should we check if the player is connected or not? even though it works without checking the player
Reply
#2

Because you only want to do stuff to players who are connected. Use foreach anyway.
Reply
#3

For most things this is indeed a redundant check since other functions also have inbuilt connection checks. Though you will need to evaluate every case separately. On a side note, I use this configuration:

pawn Код:
for(new i; i < MAX_PLAYERS; i++)
{
    if(!IsPlayerConnected(i)) continue;

    // do the stuff here.
}
In before someone comes blabbing about foreach.
Reply
#4

Thanks both.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)