Relational Operators

Computer Science: KS3, topic 2.1.5

Relational Operators

Relational operators compare two values, and produce a True or False value.

Equality

Equality

  • We can test if two values are equal using the equality operator. For example:
  • 2 == 2 would evaluate to True.
  • We can test if two values are not equal using the not-equal-to operator:
  • 2 != 2 would evaluate to False.
Comparison

Comparison

  • We can compare two numbers using the less than and greater than signs. For example:
  • 2 < 3 evaluates to True.
  • 2 > 3 evaluates to False.
  • We can test for less than or equal, or greater than or equal like this:
  • 2 <= 3 evaluates to True.
  • 3 >= 3 evaluates to True.

Test yourself on Relational Operators

  • Which of these is the correct operator for 'not equal to'?

  • Toggle until all are correct: Which of these statements evaluates to True?

  • 5 <= __
    What is the smallest integer which could make this statement True?

Practise this topic for free