Efficiency of IF statements - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Efficiency of IF statements (
/showthread.php?tid=445111)
Efficiency of IF statements -
Bharel - 19.06.2013
My question is a bit theoretical. What would be more efficient?
Using "if (bool:usuallyfalse && GetPVarInt(playerid, "bar") > 0)"
or
Код:
if (bool:usuallyfalse){
if(GetPVarInt(playerid, "bar") > 0){
Does an IF statement, check both statements when called? or does it check one after the other?
If it checks both, the second version will be more efficient. If it checks one after the other, the first version will be.
Re: Efficiency of IF statements -
Vince - 19.06.2013
You're looking in wrong places to optimize code. As for your question, try looking through pawn-lang.pdf. I think it has a section on it.
Re: Efficiency of IF statements - Emmet_ - 19.06.2013
pawn Код:
if (usuallyfalse && GetPVarInt(playerid, "bar"))
That checks if
usuallyfalse is true, and if it is true, it will execute the next statement and so on.
Re: Efficiency of IF statements -
Bharel - 19.06.2013
Quote:
Originally Posted by Vince
You're looking in wrong places to optimize code.
|
Why is that? Let's say the code is in a loop, OnPlayerUpdate, or OnPlayerTakeDamage, it's really important even in the tiny bit.
Quote:
Originally Posted by Emmet_
pawn Код:
if (usuallyfalse && GetPVarInt(playerid, "bar"))
That checks if usuallyfalse is true, and if it is true, it will execute the next statement and so on.
|
So as soon as
usuallyfalse is false, and it gets to the
&& part, it stops executing, without checking the next statement?
Re: Efficiency of IF statements -
IstuntmanI - 19.06.2013
Quote:
Originally Posted by Bharel
So as soon as usuallyfalse is false, and it gets to the && part, it stops executing, without checking the next statement?
|
Yes, try this:
Код:
if( 1 == 0 && print( "Hey" ) == 0 )
{
print( "Hi !" );
}