Comparison Operators
What you'll learn: How to use special symbols to compare two values and get a true-or-false answer.
What Are Comparison Operators?
Comparison operators (also called relational operators) let you ask yes-or-no questions about values. They compare two expressions and always produce a Boolean result: either true or false.
Think of them like a referee making calls in a game: "Is the score equal?" "Is one team ahead?" The referee gives a thumbs-up (true) or thumbs-down (false).
The Six Comparison Operators
Most programming languages use these symbols:
- Equal to:
==— "Are these two values the same?" - Not equal to:
!=— "Are these two values different?" - Less than:
<— "Is the left value smaller?" - Greater than:
>— "Is the left value larger?" - Less than or equal to:
<=— "Is the left value smaller or the same?" - Greater than or equal to:
>=— "Is the left value larger or the same?"
Examples in Plain English
5 == 5→true(five equals five)7 != 3→true(seven does not equal three)10 < 20→true(ten is less than twenty)15 > 30→false(fifteen is not greater than thirty)8 <= 8→true(eight is less than or equal to eight)4 >= 9→false(four is neither greater than nor equal to nine)
Why This Matters
You've already learned arithmetic operators (+, -, *, /) that compute new numbers. Comparison operators are different: they evaluate relationships and give you Boolean answers. These true/false results become the foundation for making decisions in programs—something you'll explore in future lessons.
Key Takeaway: Comparison operators (==, !=, <, >, <=, >=) compare two values and always return a Boolean (true or false), enabling programs to evaluate conditions.