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.