Given:
var x = 2;
if (x >= 1)
// do stuff
if (x > 0)
// do stuff
Both conditions will be true, but is there a difference in terms of performance? Should one be used over the other in terms of standardization?
Given:
var x = 2;
if (x >= 1)
// do stuff
if (x > 0)
// do stuff
Both conditions will be true, but is there a difference in terms of performance? Should one be used over the other in terms of standardization?
I personally prefer x > 0
, because it is easier to read.
In terms of performance I'm almost confident that they're equal. That being said, I think the most important thing is to consistently use either style.
The >= means if the first statement is larger of equal to. The > means if the first state ment is larger.
for example:
x=4;
if( x >= 4 ){
echo "This is TRUE since x is bigger OR equal to 4";
}
if( x > 4 ){
echo "This is FALSE since x isn't bigger than 4, it is 4.";
}
if( x <= 4){
echo "This is TRUE since x is smaller or equal to 4.";
}
if( x < 4){
echo "This is FALSE since x isn't smaller than 4.";
}