Introduction
Comparison instructions help decide if one value is equal, not equal, greater, or less than another. This lets the program make choices like a traffic light or a vending machine.
EQ(source1, source2) // Equal NE(source1, source2) // Not Equal GT(source1, source2) // Greater Than LT(source1, source2) // Less Than
EQ(temperature, 100)NE(sensorValue, 0)GT(counter, 10)LT(timer, 5)VAR temperature : INT := 95; alarm : BOOL := FALSE; END_VAR // Check if temperature is greater than 90 IF GT(temperature, 90) THEN alarm := TRUE; ELSE alarm := FALSE; END_IF // Output alarm status // (In real PLC, this might turn on a light) // Print alarm status (simulated) PRINT('Alarm status: ' + TO_STRING(alarm));
VAR X: INT := 5; Y: INT := 10; Result: BOOL; END_VAR Result := X LT Y;
Result after execution?IF A NEQ B THEN // do something END_IF
Pass the test and this pattern moves unknown