Bird
Raised Fist0
PLC Programmingscripting~10 mins

Comparison instructions (EQ, NE, GT, LT) in PLC Programming - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Comparison instructions (EQ, NE, GT, LT)
Start
↓
Read Inputs
↓
Compare Values
↓
Set EQ Flag
↓
Set NE Flag
↓
Set GT Flag
↓
Set LT Flag
↓
No Condition Met
↓
Output Flags
↓
End
The PLC reads two values, compares them using EQ, NE, GT, LT instructions, sets the corresponding flag, then outputs the result.
Execution Sample
PLC Programming
IF A EQ B THEN
  EQ_Flag := TRUE;
ELSIF A NE B THEN
  NE_Flag := TRUE;
ELSIF A GT B THEN
  GT_Flag := TRUE;
ELSIF A LT B THEN
  LT_Flag := TRUE;
END_IF;
This code compares two values A and B using EQ, NE, GT, LT and sets the matching flag to TRUE.
Execution Table
StepCondition CheckedCondition ResultFlag SetNotes
1A EQ BFalseNoneA=5, B=7, 5 equals 7? No
2A NE BTrueNE_Flag5 not equal 7? Yes, NE_Flag set to TRUE
3SkippedSkippedSkippedSince NE was true, other checks skipped
4SkippedSkippedSkippedNo further checks
5SkippedSkippedSkippedEnd of comparison
💡 NE condition true at step 2, so later conditions are not checked.
Variable Tracker
VariableStartAfter Step 1After Step 2Final
A5555
B7777
EQ_FlagFALSEFALSEFALSEFALSE
NE_FlagFALSEFALSETRUETRUE
GT_FlagFALSEFALSEFALSEFALSE
LT_FlagFALSEFALSEFALSEFALSE
Key Moments - 3 Insights
Why does the program stop checking after NE is true?
Because the comparison uses ELSE IF structure, once a condition is true (NE at step 2), the rest are skipped as shown in execution_table rows 3-5.
Can EQ and NE both be true at the same time?
No, EQ means equal and NE means not equal, they are opposites. The execution_table shows only one flag set per run.
What happens if A equals B?
At step 1, EQ condition would be true, EQ_Flag set to TRUE, and other conditions skipped as per execution_table logic.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of NE_Flag after step 2?
AFALSE
BTRUE
CUNKNOWN
DNot Set
💡 Hint
Check the 'Flag Set' column at step 2 in execution_table.
At which step does the program stop checking further conditions?
AStep 1
BStep 3
CStep 2
DStep 5
💡 Hint
Look at the 'Notes' column in execution_table rows 3-5.
If A was 7 and B was 7, which flag would be set according to the execution flow?
AEQ_Flag
BNE_Flag
CGT_Flag
DLT_Flag
💡 Hint
Refer to the logic in execution_sample and key_moments about EQ condition.
Concept Snapshot
Comparison instructions check two values:
EQ = equal, NE = not equal,
GT = greater than, LT = less than.
Only one condition sets its flag per check.
Checks stop after first true condition.
Used to control PLC logic flow.
Full Transcript
This visual execution shows how PLC comparison instructions EQ, NE, GT, and LT work. The program reads two values, compares them step-by-step. It first checks if A equals B (EQ). If false, it checks if A is not equal to B (NE). If NE is true, it sets the NE_Flag and skips other checks. This prevents multiple flags from being set at once. The variable tracker shows flags start false and only the matching flag becomes true. Key moments clarify why checks stop after one true condition and that EQ and NE cannot both be true. The quiz tests understanding of flag values and flow control. This helps beginners see exactly how PLC comparisons run step-by-step.

Practice

(1/5)
1. Which comparison instruction checks if two values are exactly the same in PLC programming?
easy
A. EQ
B. NE
C. GT
D. LT

Solution

  1. Step 1: Understand the meaning of EQ

    EQ stands for 'equal' and checks if two values are exactly the same.
  2. Step 2: Compare with other instructions

    NE means not equal, GT means greater than, and LT means less than, so they do not check equality.
  3. Final Answer:

    EQ -> Option A
  4. Quick Check:

    EQ means equal [OK]
Hint: EQ means equal, so it checks if values match exactly [OK]
Common Mistakes:
  • Confusing EQ with NE
  • Thinking GT checks equality
  • Mixing LT with EQ
2. Which of the following is the correct syntax to check if variable A is greater than variable B in a PLC program?
easy
A. IF A LT B THEN
B. IF A NE B THEN
C. IF A EQ B THEN
D. IF A GT B THEN

Solution

  1. Step 1: Identify the comparison for 'greater than'

    GT means 'greater than', so to check if A is greater than B, use 'A GT B'.
  2. Step 2: Check other options

    LT means less than, EQ means equal, NE means not equal, so they are incorrect for this check.
  3. Final Answer:

    IF A GT B THEN -> Option D
  4. Quick Check:

    GT means greater than [OK]
Hint: GT means greater than, so use it to compare if A > B [OK]
Common Mistakes:
  • Using LT instead of GT
  • Confusing EQ with GT
  • Using NE for greater than check
3. Given the following PLC code snippet:
VAR
  X: INT := 5;
  Y: INT := 10;
  Result: BOOL;
END_VAR

Result := X LT Y;

What will be the value of Result after execution?
medium
A. Syntax Error
B. FALSE
C. TRUE
D. Undefined

Solution

  1. Step 1: Understand the comparison LT

    LT means 'less than'. The code checks if X (5) is less than Y (10).
  2. Step 2: Evaluate the condition

    Since 5 is less than 10, the condition is true, so Result will be TRUE.
  3. Final Answer:

    TRUE -> Option C
  4. Quick Check:

    5 LT 10 = TRUE [OK]
Hint: LT means less than; 5 < 10 is true [OK]
Common Mistakes:
  • Thinking LT means greater than
  • Assuming Result is FALSE
  • Confusing syntax with error
4. Identify the error in this PLC comparison instruction:
IF A NEQ B THEN
  // do something
END_IF
medium
A. Missing THEN keyword
B. NEQ is not a valid comparison instruction
C. Comparison should be EQ instead of NEQ
D. IF statement missing parentheses

Solution

  1. Step 1: Check the comparison instruction used

    The code uses 'NEQ' which is not a standard PLC comparison instruction.
  2. Step 2: Identify correct instruction

    The correct instruction for 'not equal' is 'NE', not 'NEQ'.
  3. Final Answer:

    NEQ is not a valid comparison instruction -> Option B
  4. Quick Check:

    Use NE for not equal, not NEQ [OK]
Hint: Use NE for not equal, not NEQ [OK]
Common Mistakes:
  • Using NEQ instead of NE
  • Forgetting THEN keyword
  • Adding unnecessary parentheses
5. You want to write a PLC program that turns on a motor only if the temperature is greater than 50 and the pressure is less than 100. Which combination of comparison instructions correctly checks this condition?
hard
A. IF Temperature GT 50 AND Pressure LT 100 THEN Motor := TRUE;
B. IF Temperature LT 50 OR Pressure GT 100 THEN Motor := TRUE;
C. IF Temperature EQ 50 AND Pressure EQ 100 THEN Motor := TRUE;
D. IF Temperature NE 50 AND Pressure NE 100 THEN Motor := TRUE;

Solution

  1. Step 1: Translate the condition into comparisons

    The motor should turn on if temperature is greater than 50 (GT 50) and pressure is less than 100 (LT 100).
  2. Step 2: Check each option

    IF Temperature GT 50 AND Pressure LT 100 THEN Motor := TRUE; uses GT and LT with AND, matching the condition exactly. Other options use wrong comparisons or OR instead of AND.
  3. Final Answer:

    IF Temperature GT 50 AND Pressure LT 100 THEN Motor := TRUE; -> Option A
  4. Quick Check:

    GT and LT with AND matches condition [OK]
Hint: Use GT for greater, LT for less, combine with AND for both conditions [OK]
Common Mistakes:
  • Using OR instead of AND
  • Using EQ instead of GT or LT
  • Mixing NE with equality checks
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard