Computer Science
Forgetting Boolean Operator Precedence
Students write mixed AND and OR conditions without parentheses and expect them to run left to right.
Quick check
Why students make it
They read the condition like an English sentence and group the words mentally. Since AND and OR are both logical connectors, they may assume they have the same priority.
The rule done right
Most languages evaluate NOT first, then AND, then OR. In Python this is not, and, or; in Java, JavaScript, and C-style languages this is !, &&, ||.
Related resources
- Boolean Logic & Binary Cheat Sheet
- Programming Fundamentals Cheat Sheet
- JavaScript Essentials Cheat Sheet
- Python Syntax Quick Reference Cheat Sheet
- Java Syntax Quick Reference Cheat Sheet
- Computer Science, Logic Gates Worksheet
- CS, Loops and Control Flow Worksheet
- CS: SQL: SELECT, WHERE, JOIN Worksheet
- Truth Table Generator Tool
- Logic Gate Circuit Simulator Tool
- If/Then Choice Builder Tool
- Debugging & Unit Testing Explorer Tool
- Selection & Iteration Lab Lab
- Boolean Algebra & Logic Gates Lab Lab
- Selection & Iteration Code Tracing Lab Lab
- If/Then Choice Lab Lab
- Debugging & Unit Testing Lab Lab