Silverfrost Forums

Welcome to our forums

Programing doubts with IF and .AND.

29 May 2008 4:42 #3281

Hi,

I found a problem that drive me crazy and i can´t find the way to short it out, here it is:

I created an IF statment and I would like to use .AND. into the logical statment as I show below: DO i = 1, siz Diff(i)= Frct(i) - Obs(i) IF (ABS(Diff(i)) ⇐ Threshold) THEN x(1)=x(1)+1

ELSE IF (Diff(i) > Threshold) THEN 
  x(2)=x(2)+1
 
  ELSE IF (Diff(i) < -Threshold) THEN
   x(3)=x(3)+1
 
  ELSE IF (ABS(Diff(i)) <= Threshold .AND. ABS(Frct(i)) <= Threshold) THEN  !NO ESTA CORRECTO, I should think about
    x(4)=x(4)+1
     
    END IF
    END DO

The point is: the program just forgets thte statmentment that is after .AND. My question is: How could I write the statment to match all statments??? Thaqnks in advance

29 May 2008 5:53 #3282

Sorry, but it´s still not clear to me......, would you mind an expanded explanation??? thanks

30 May 2008 10:40 #3284

Thanks I got it!!!,

I understood what you was saying in the first post: In the way it was wrote, the last condition will never be executed. I re-wrote the code and now is working perfectly, here it is:

DO i = 1, siz Diff(i)= Frct(i) - Obs(i) IF (ABS(Diff(i)) ⇐ Threshold .AND. ABS(Frct(i)) ⇐ Threshold) THEN x(4)=x(4)+1

ELSE IF (Diff(i) > Threshold) THEN 
  x(2)=x(2)+1
 
  ELSE IF (Diff(i) < -Threshold) THEN
   x(3)=x(3)+1
 
  ELSE IF (ABS(Diff(i)) <= Threshold) THEN  
    x(1)=x(1)+1
     
    END IF
    END DO

Thanks very much

Please login to reply.