Operators: Relational, Logical, and Arithmetic

Master the essential tools that power all programming operations!

1

The Tools of the Trade

Operators are symbols used to perform specific mathematical or logical manipulations on data (operands). Think of them as the "verbs" of programming — they tell the computer what action to perform.

The Three Categories

Arithmetic Operators

Used for calculations like addition, subtraction, multiplication, and division

Relational Operators

Used to compare two values, always returning True or False

Logical Operators

Used to combine multiple conditions for complex decision-making

Interactive: Operator Sort

Click on each symbol to sort it into the correct category!

+
>
AND
*
<=
OR
-
<>
NOT
/

Arithmetic

Relational

Logical

2

Arithmetic Operators (Calculations)

Arithmetic operators perform basic mathematical calculations on numbers.

The Basics

+ Addition

Adds two values (e.g., 5 + 3 = 8)

- Subtraction

Subtracts one value from another (e.g., 10 - 4 = 6)

* Multiplication

Multiplies two values (e.g., 6 * 7 = 42)

/ Division

Divides one value by another (e.g., 15 / 3 = 5)

Integer Division & Remainder

When working with whole numbers, two additional operators become important:

7 DIV 2 = 3

DIV returns the whole number part of division (ignores the remainder).

7 MOD 2 = 1

MOD returns just the remainder after division.

Order of Operations (BODMAS/PEMDAS)

When an expression has multiple operators, they are evaluated in this order:

  • Brackets/Parentheses - Calculations inside () are done first
  • Orders/Exponents - Powers and square roots
  • Division & Multiplication - Left to right
  • Addition & Subtraction - Left to right
Interactive: The Modulo Machine

Enter two numbers to see how DIV and MOD work!

÷
💡 Real-world use: 17 is odd (remainder 1). If MOD 2 = 0, the number is even!
3

Relational Operators (Comparisons)

Relational operators compare two values. The result is always a Boolean — either True or False.

The Comparison Symbols

> Greater than

True if left is greater (e.g., 10 > 5 = True)

< Less than

True if left is smaller (e.g., 3 < 8 = True)

>= Greater than or equal

True if left is greater or equal (e.g., 5 >= 5 = True)

<= Less than or equal

True if left is smaller or equal (e.g., 7 <= 10 = True)

= Equal to

True if both values are equal (e.g., 6 = 6 = True)

<> Not equal to

True if values are different (e.g., 4 <> 9 = True)

Interactive: True or False Challenge

Click True or False as fast as you can! Beat the timer!

⏱️ 30 seconds
15 <= 10
Score: 0 | Streak: 0
4

Logical Operators (Joining Decisions)

Logical operators combine multiple conditions to make complex decisions. They're essential for filtering and multi-criteria checks.

The Big Three

AND

True only if BOTH conditions are true

OR

True if AT LEAST ONE condition is true

NOT

Reverses the result (True becomes False)

The Truth Table

A truth table shows all possible combinations of inputs and their results:

A B A AND B A OR B NOT A
True True True True False
True False False True False
False True False True True
False False False False True
Interactive: The Logic Gate

Toggle the switches to see how current flows through AND vs OR gates!

A B AND LIGHT
Switch A
Switch B
Light is OFF 💡

Current flows only when the logic condition is met

5

Combining Operators (The Mega-Expression)

Real programs often combine multiple operators in complex expressions. Understanding precedence is crucial!

Complex Logic Example

IF (Age > 18) AND (Has_License = True) THEN Output "You can drive!" ENDIF

Operator Precedence Order

When all three types appear together, this is the order in which they're evaluated:

  1. Arithmetic (calculations first)
  2. Relational (comparisons second)
  3. Logical (AND, OR, NOT last)
Interactive: The Expression Solver

Click on the part of the expression that would be calculated FIRST, then SECOND, etc.

(5 + 3) * 2 > 10 AND 8 = 8
6

CSEC Exam Pitfalls

These common mistakes trip up many students on exams. Learn to avoid them!

The "Assignment vs. Equality" Confusion

Assignment (=)

SET X = 5 means "store the value 5 in variable X"

Comparison (=)

IF X = 5 means "check if X equals 5 (True/False)"

Remember: In pseudocode, "=" can mean assignment, but in conditions it means comparison. Context matters!

The Range Trap

WRONG: IF 18 < Age < 25

This doesn't work because the computer evaluates 18 < Age first, getting True or False, then tries to compare that to 25.

CORRECT: IF (Age > 18) AND (Age < 25)

Each comparison is evaluated separately, then combined with AND.

7

Knowledge Check: Operator Expert

Test Your Understanding

Question 1: Calculation Quiz

What is the result of 15 MOD 4?

A 3.75
B 3
C 2
D 1

Question 2: Logic Challenge

If A = True and B = False, what is the result of (A AND B) OR (NOT B)?

A True
B False
C Cannot be determined
D Error

Question 3: Short Answer

Explain a real-world scenario where a programmer would use the MOD operator.

Scroll to Top