if else

 

Is this code correct? It will do 1 OR the other?

I had a problem with if else statements the other day so just checking:


      if (R1-OvernightHigh<0.0048 && R1>OvernightHigh)
      {
         OvernightHigh=R1;
      }
      else if (R2-OvernightHigh<0.0048 && R2>OvernightHigh)
      {
         OvernightHigh=R2;
      }
 
SanMiguel:

Is this code correct? It will do 1 OR the other?

I had a problem with if else statements the other day so just checking:


First statement will fire if first condition is met.

Second statement will fire if a) first condition is not met AND b) second condition is met.

Since both statements write the same variable, the "else" is superfluous.


CB

 
cloudbreaker:

First statement will fire if first condition is met.

Second statement will fire if a) first condition is not met AND b) second condition is met.

Since both statements write the same variable, the "else" is superfluous.


CB

they write to the same variable but with different values depending on the if.

Reason: