Course Content
Computer Science 2010 : Olevel : Free Trail Course

Relational operators in programming are used to establish relationships between values and evaluate the truth of conditions. These operators include greater than (>), less than (<), greater than or equal to (>=), less than or equal to (<=), equal to (==), and not equal to (!=) some time written as <> in pseudocode.

In simple conditions, relational operators help determine the validity of statements by comparing values. For instance, in a program that calculates grades based on exam scores, a relational operator could be used to check if a student’s score is greater than or equal to the passing threshold.

In another scenario, relational operators might be employed to compare the ages of two individuals to determine who is older. These operators play a fundamental role in decision-making processes within programs, enabling developers to create logic that responds dynamically to different data conditions.

here are five examples of relational operators:

Greater Than (>):

x = 10
y = 5
result = x > y # result will be True

In this example, the greater than operator (>) compares whether the value of x (10) is greater than the value of y (5). The result is True because 10 is indeed greater than 5.

Less Than (<):

a = 7
b = 12
result = a < b # result will be True

Here, the less than operator (<) compares whether the value of a (7) is less than the value of b (12). The result is True because 7 is less than 12.

Greater Than or Equal To (>=):

m = 15
n = 15
result = m >= n # result will be True

This example compares whether the value of m (15) is greater than or equal to the value of n (15). Since they are equal, the result is True.

Less Than or Equal To (<=):

p = 20
q = 25
result = p <= q # result will be True

In this case, the less than or equal to operator (<=) checks if the value of p (20) is less than or equal to the value of q (25). As 20 is less than 25, the result is True.

Equal To (==):

num1 = 10
num2 = 10
result = num1 == num2 # result will be True

Here, the equal to operator (==) verifies if the value of num1 (10) is equal to the value of num2 (10). Since they are indeed equal, the result is True.

These examples demonstrate how relational operators are used to compare values in programming and determine the truth of conditions based on those comparisons.