Comparing arrays

drChiavo
2016-01-29
2016-01-30
  • drChiavo - 2016-01-29

    Hello,

    I want to compare some arrays but what I'm doing is not working.

    Here is my code:

    VAR   
       i               : INT;   
       xValueChanged              : BOOL;
       xInitialStatusSensor      : ARRAY [0..5] OF BOOL := [TRUE, FALSE , TRUE, FALSE, FALSE];
       xRunTimeStatusSensor      : ARRAY [0..5] OF BOOL := [TRUE, FALSE , FAlSE, FALSE, FALSE];
    END_VAR
    FOR i:= 0 TO 5 DO
       
       IF xInitialStatusSensor[i] <> xRunTimeStatusSensor[i]  THEN
             
          xValueChanged := TRUE;
       ELSE
             
          xValueChanged := FALSE;
          
       END_IF
    END_FOR
    

    Any idea?
    Thanks in advanced

     
  • TimvH

    TimvH - 2016-01-30

    In the last cycle of your FOR loop the result is determined.
    Maybe better to use e.g.:

    xValueChanged := FALSE;
    FOR i:= 0 TO 5 DO
       IF xInitialStatusSensor[i] <> xRunTimeStatusSensor[i]  THEN
          xValueChanged := TRUE;
         // EXIT optionally 
       END_IF
    END_FOR
    
     

Log in to post a comment.