⬅ Previous Topic
Arithmetic OperatorsNext Topic ⮕
Logical Operators - AND, OR, NOT⬅ Previous Topic
Arithmetic OperatorsNext Topic ⮕
Logical Operators - AND, OR, NOTComparison operators are used to compare two values or expressions. They always return a boolean value: either true
or false
. These operators are essential in decision-making logic like conditions and loops.
==
: Equal to!=
: Not equal to>
: Greater than<
: Less than>=
: Greater than or equal to<=
: Less than or equal to==
(Equal To)SET a TO 5
SET b TO 5
IF a == b THEN
PRINT "a and b are equal"
ELSE
PRINT "a and b are not equal"
END IF
a and b are equal
Question: What happens if a
was 5 and b
was 10?
Answer: The result would be false
, so it would print "a and b are not equal"
.
!=
(Not Equal To)SET x TO 10
SET y TO 20
IF x != y THEN
PRINT "x and y are different"
ELSE
PRINT "x and y are the same"
END IF
x and y are different
>
and <
SET age TO 18
IF age > 21 THEN
PRINT "You are allowed entry"
ELSE
PRINT "Entry denied"
END IF
Entry denied
Question: Why was entry denied even though age is 18?
Answer: Because the condition checks if age > 21
, and 18 is not greater than 21.
>=
and <=
SET marks TO 75
IF marks >= 60 THEN
PRINT "You passed"
ELSE
PRINT "You failed"
END IF
You passed
Tip: Use >=
when you want to include the boundary value as valid. In this case, even 60 would result in "You passed".
They are primarily used in:
true
or false
.>=
vs >
).Understanding how these operators work is important before diving into more advanced topics like loops, functions, or algorithms.
⬅ Previous Topic
Arithmetic OperatorsNext Topic ⮕
Logical Operators - AND, OR, NOTYou can support this website with a contribution of your choice.
When making a contribution, mention your name, and programguru.org in the message. Your name shall be displayed in the sponsors list.