What is the better way to use loop? continue or if.
#1

Hey.
What is the better and fast way to use loop?

PHP Code:
for(new ...) if(IsPlayerConnected(i))

or

PHP Code:
for(new ...) 
{
        if(!
IsPlayerConnected(i)) continue; 
and to use MAX_PLAYERS or GetMaxPlayers()?
Reply
#2

The second way creates in my mind this thought: Travelling from Europe to America through Russia.
Reply
#3

Be more specific please, XD.
So the second way is better?

and about GetMaxPlayers(), someone told me that MAX_PLAYERS is better, this is right?
Reply
#4

So if you live in Europe, and want to travel to america, you will firstly go to russia? I think the second way is more complicated, that's all. And about the max_players:
You either use
pawn Code:
for (new i=0; i<MAX_PLAYERS; i++)
{
    if (IsPlayerConnected(i))
    {
Or Y_Less's include
pawn Code:
foreach (new i : Player)
{
Reply
#5

Thank you. +REP
Reply
#6

You are best off using the foreach include, simply put, it loops only through connected players, and not through all players like a standard for-player-loop. Continue; is just skipping the loop iteration, in theory it's still doing the same thing (checking if the player is connected or not). I suppose it might be a bit faster but I doubt it'd be measurable.
Reply
#7

Okay, thank you, also playbox.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)