What is the better way to use loop? continue or if. -
Activest - 22.04.2013
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()?
AW: What is the better way to use loop? continue or if. -
HurtLocker - 22.04.2013
The second way creates in my mind this thought: Travelling from Europe to America through Russia.
Re: What is the better way to use loop? continue or if. -
Activest - 22.04.2013
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?
AW: What is the better way to use loop? continue or if. -
HurtLocker - 22.04.2013
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)
{
Re: What is the better way to use loop? continue or if. -
Activest - 22.04.2013
Thank you. +REP
Re: What is the better way to use loop? continue or if. -
playbox12 - 22.04.2013
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.
Re: What is the better way to use loop? continue or if. -
Activest - 22.04.2013
Okay, thank you, also playbox.