Efficiency of IF statements
#1

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.
Reply
#2

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.
Reply
#3

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.
Reply
#4

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?
Reply
#5

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 !" );
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)