Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using "OR" within an "IF" statement

Sorry this is a really simple question, but i just cant figure it. Im attempting to use nested IF statements with an OR condition inside. This is the code:

if (positionE != -1){
   if (position == -1) || if (positionE < position)
                   position = positionE;
}

Obviously Im using the OR conditon incorrectly, please could someone point out the correct use.

This is the psuedo-code Im trying to code:

If positionE is not -1  
   If position is -1 or positionE is less than position  
      position is positionE 
like image 872
user3431630 Avatar asked Apr 19 '26 11:04

user3431630


1 Answers

Try this :

if(positionE != -1 && (position == -1 || positionE < position)){
   position = positionE;
}
like image 106
Aduait Pokhriyal Avatar answered Apr 21 '26 00:04

Aduait Pokhriyal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!