Need Explanation With 'for' statement!
#9

This will loop for 21 players - IDs: 0-20
pawn Код:
for(new i = 0; i < 21; i++)
{
  if(IsPlayerConnected(i)) SendClientMessage(i, 0xAA000AA, "HAHA!");
}
This will loop for 22 players - IDs: 0-21
pawn Код:
for(new i = 0; i <= 21; i++)
{
  if(IsPlayerConnected(i)) SendClientMessage(i, 0xAA000AA, "HAHA!");
}
The only difference in this code from the first one is that i've used <= so this means if i is smaller than 21 or equal to 21.

And i suggest to you to use ******'s foreach include - it's faster than normal for loop and you don't have to use IsPlayerConnected function because foreach already has this check in its code.

foreach include - http://forum.sa-mp.com/index.php?topic=117573.0

Example with foreach:
pawn Код:
foreach(Player, i) SendClientMessage(i, 0xAA000AA, "HAHA!");
Reply


Messages In This Thread
Need Explanation With 'for' statement! - by Micko9 - 16.03.2010, 17:56
Re: Need Explanation With 'for' statement! - by Correlli - 16.03.2010, 18:01
Re: Need Explanation With 'for' statement! - by ¤Adas¤ - 16.03.2010, 18:01
Re: Need Explanation With 'for' statement! - by Micko9 - 16.03.2010, 18:22
Re: Need Explanation With 'for' statement! - by ¤Adas¤ - 16.03.2010, 18:23
Re: Need Explanation With 'for' statement! - by Micko9 - 16.03.2010, 18:40
Re: Need Explanation With 'for' statement! - by Correlli - 16.03.2010, 18:42
Re: Need Explanation With 'for' statement! - by Micko9 - 16.03.2010, 18:46
Re: Need Explanation With 'for' statement! - by Correlli - 16.03.2010, 18:55

Forum Jump:


Users browsing this thread: 1 Guest(s)