Computer Science
Confusing Assignment with Comparison
Students write x = 5 inside a condition when they mean to test whether x is 5.
Quick check
Why students make it
In math, = often reads like "is equal to," so it feels natural to use it for a test. In most programming languages, assignment changes a variable, while comparison produces a Boolean value.
The rule done right
Use assignment when you want to store or update a value, and use comparison when you want a true-or-false test. In many languages, = assigns and == compares.
Related resources
- Boolean Logic & Binary Cheat Sheet
- Programming Fundamentals Cheat Sheet
- Algorithms & Big-O Notation Cheat Sheet
- CS, Loops and Control Flow Worksheet
- CS, Functions and Parameters Worksheet
- CS, Java, Classes, Methods, and Public Static Void Main Worksheet
- Computer Science, Logic Gates Worksheet
- Debugging & Unit Testing Explorer Tool
- Java Strings & Methods Explorer Tool
- Truth Table Generator Tool
- Logic Gate Circuit Simulator Tool
- Selection & Iteration Code Tracing Lab Lab
- Selection & Iteration Lab Lab
- Debugging & Unit Testing Lab Lab
- Java Strings Lab Lab