</>Learn to Write Code
LearnPseudocodeReal CodeLanguagesVideosCode TalkAbout
Learn → Programming Fundamentals → Operators & Comparisons

Programming Fundamentals

01Variables02Operators03Input & Output04Sequence05Conditions06Loops07Functions08Objects
Lesson 2 of 8·Beginner

Operators & Comparisons

Use values to calculate answers and compare one value with another.

Related:operatorcomparisonmodulusgreater thanless than

Operators do work with values

An operator tells the computer to do something with one or more values. Some operators calculate a new value. Others ask a yes-or-no question about values.

For example, + adds numbers. MODULUS gives the remainder after division. GREATER THAN asks whether one value is larger than another.

  • 8 + 4 produces 12.
  • 10 MODULUS 3 produces 1.
  • 12 GREATER THAN 10 produces true.
Try it: What remainder should 17 MODULUS 5 produce?

Calculate first, compare second

We can describe the calculations and comparisons without worrying about language-specific punctuation.

Pseudocode
CREATE total AS 8 + 4
CREATE remainder AS 10 MODULUS 3
CREATE isHighScore AS total GREATER THAN 10

SHOW total
SHOW remainder
SHOW isHighScore
A comparison produces a boolean-style result: true or false.

The same idea in Python

Python uses % for modulus and > for greater than.

Python
total = 8 + 4
remainder = 10 % 3
isHighScore = total > 10

print(total)
print(remainder)
print(isHighScore)

The same idea in JavaScript

JavaScript uses the same % and > symbols for these operations.

JavaScript
const total = 8 + 4;
const remainder = 10 % 3;
const isHighScore = total > 10;

console.log(total);
console.log(remainder);
console.log(isHighScore);

The same idea in C#

C# stores the comparison result in a bool.

C#
int total = 8 + 4;
int remainder = 10 % 3;
bool isHighScore = total > 10;

Console.WriteLine(total);
Console.WriteLine(remainder);
Console.WriteLine(isHighScore);

The same idea in Java

Java uses boolean for a true-or-false value.

Java
int total = 8 + 4;
int remainder = 10 % 3;
boolean isHighScore = total > 10;

System.out.println(total);
System.out.println(remainder);
System.out.println(isHighScore);

The same idea in C++

C++ uses bool for the comparison result.

C++
int total = 8 + 4;
int remainder = 10 % 3;
bool isHighScore = total > 10;

std::cout << total << '\n';
std::cout << remainder << '\n';
std::cout << std::boolalpha << isHighScore << '\n';
Lesson 2 of 8 · Concept
← Previous Lesson: VariablesNext Lesson: Input & Output →

Learn to Write Code

Learn the idea first, write it in pseudocode, then see how real programming languages express the same logic.

Learn

CurriculumPseudocode StandardLanguagesReal Code

Elsewhere

Code TalkAbout BriancodeBetter on YouTubeSupporting files on GitHubAdvertising & Promotions
© 2026 Learn to Write Code. Educational content and examples are provided for learning purposes.