🤔 Logic Error
5th Grade 💻 Coding
A logic error is a bug where the program runs all the way through without any error message, but does something different from what you meant.
The computer can’t catch a logic error on its own, because as far as it’s concerned everything is fine: the instructions are written correctly, and it follows them exactly. The problem is in the thinking — in the instructions themselves. For example, you wrote a minus instead of a plus, forgot to reset a counter, or checked “greater than” instead of “greater than or equal to.”
To find logic errors, you test the program with inputs whose answers you already know: if the average of 80 and 90 comes out as 170, something is wrong. Tracing, printing values along the way and testing edge cases are the main tools.
For example
- A grade-average calculator forgot to divide by the number of grades — so it shows the total instead of the average.
- In a game, the score goes down when you collect a coin because someone wrote
score - 1instead ofscore + 1.
📌 Remember: Logic error = the computer obeys perfectly, but the instruction is wrong.
Quick quiz
What is special about a logic error?
How do you find a logic error?
The average of 80 and 90 came out as 170. What is the likely bug?