In AP Computer Science Principles, a logic error is a mistake in an algorithm or program that causes it to behave incorrectly or unexpectedly, even though the code runs without crashing (EK CRD-2.I.1). The program does exactly what you wrote, just not what you meant.
A logic error is a mistake in an algorithm or program that causes it to behave incorrectly or unexpectedly (EK CRD-2.I.1). Here's the sneaky part. Code with a logic error usually looks fine and runs fine. The computer doesn't complain at all. It just gives you the wrong answer, because the computer faithfully executes the instructions you actually wrote, not the instructions you meant to write.
Classic examples are dividing by 2 instead of 3 when averaging three test scores, writing > when you meant >=, or checking only year % 4 == 0 for leap years (which wrongly calls 1900 a leap year). Because nothing crashes, the only way to catch a logic error is testing. You feed the program defined inputs, compare the actual output to the expected output, and revise when they don't match (EK CRD-2.J.1). That's why Topic 1.4 pairs error types with testing strategy. They're two halves of the same skill.
Logic errors live in Topic 1.4 (Identifying and Correcting Errors) in Unit 1: Creative Development, under learning objective AP Comp Sci P 1.4.A, which says you need to both identify an error and correct it. The CED defines four error types side by side (logic, syntax, run-time, and overflow), and the exam loves asking you to tell them apart. Logic errors also connect directly to AP Comp Sci P 1.4.B, choosing inputs and expected outputs to check correctness, because testing is the only reliable way to expose a logic error. This matters beyond multiple choice. The Create performance task and the written response questions ask you to reason about whether your own procedure behaves correctly, which is logic-error detection applied to your own code.
Keep studying AP® Computer Science Principles Unit 1
Syntax error (Unit 1)
Syntax errors break the rules of the programming language, so the program won't even run (EK CRD-2.I.2). A logic error is the opposite situation. The grammar is perfect but the meaning is wrong. Think of it as a sentence that's grammatically correct but says something false.
Run-time error (Unit 1)
A run-time error happens while the program is executing, like dividing by zero or indexing past the end of a list (EK CRD-2.I.3). It crashes the program. A logic error never crashes anything, which is exactly why it's harder to spot. One stops the show, the other quietly lies to you.
Testing with defined inputs (Topic 1.4, Unit 1)
Logic errors are why testing exists. Under AP Comp Sci P 1.4.B, you pick inputs that demonstrate different expected outcomes, especially values at or just beyond the extremes of the input range (EK CRD-2.J.2). Edge cases like 0, the last list index, or the year 1900 are where logic errors love to hide.
Iterative development process (Unit 1)
In the development process from earlier in Unit 1, you test, find that actual output doesn't match expected output, then revise. That find-and-fix loop is the whole life cycle of a logic error, and it's the workflow the Create task expects you to describe.
Multiple-choice questions typically show you a short program plus its wrong behavior and ask you to classify or fix the error. Common stems include a program that averages three scores but divides by 2 instead of 3 (classify the error type), a findMax loop that uses i <= numbers.length and runs one index too far (spot the logic error), a prime checker that passes 2, 3, 5, and 7 but fails on 9 and 11 (infer the most likely flaw from test results), and a leap year function that only checks divisibility by 4 (identify what's missing). Notice the pattern. You're given evidence, often test results, and you have to reason backward to the bug. On the written response section, the 2025 exam (Written Q1 and Q2) asked about selection statements from your Personalized Project Reference, which means explaining what your code actually does versus what it should do. That's logic-error analysis on your own program.
A syntax error breaks the language's rules, like a missing parenthesis, so the program won't run at all and the computer usually points right at the problem. A logic error follows every rule perfectly, runs without complaint, and produces wrong output. Quick test for the exam. If the question says the code runs but gives an incorrect or unexpected result, it's a logic error. If the code won't run because the language rules were violated, it's a syntax error.
A logic error is a mistake that causes a program to behave incorrectly or unexpectedly, even though the code runs without crashing (EK CRD-2.I.1).
The fastest way to classify an error on the exam is to ask whether the code runs. Wrong output from running code means logic error; code that won't run means syntax error; a crash during execution means run-time error.
Logic errors can only be caught by testing, comparing actual outputs against expected outputs for defined inputs (EK CRD-2.J.1).
Test inputs at and just beyond the extremes of the input range, because edge cases like the first index, the last index, and boundary values are where logic errors usually hide (EK CRD-2.J.2).
Classic logic errors on AP CSP questions include off-by-one loop bounds (using <= instead of <), wrong operators or constants (dividing by 2 instead of 3), and incomplete conditions (checking only divisibility by 4 for leap years).
It's a mistake in an algorithm or program that causes incorrect or unexpected behavior, as defined in EK CRD-2.I.1 under Topic 1.4. The code runs fine, but the output is wrong because the instructions don't match the programmer's intent.
No, and that's the defining feature. The program runs to completion and produces output, just the wrong output. If the program crashes during execution, that's a run-time error instead (EK CRD-2.I.3).
A syntax error violates the programming language's rules, so the code won't run (EK CRD-2.I.2). A logic error follows all the rules but encodes the wrong idea, so the code runs and gives an incorrect result. Dividing three test scores by 2 instead of 3 is a logic error, not a syntax error.
Test it. Run the program with defined inputs where you already know the expected output, then compare (EK CRD-2.J.1). Prioritize inputs at or just beyond the extremes of the valid range, since boundary cases like 0, the last list index, or the year 1900 expose most logic errors.
Off-by-one loop conditions (i <= length instead of i < length), wrong numbers or operators (dividing by 2 instead of 3 when averaging three values), and incomplete conditionals (a leap year check that only tests year % 4 == 0). Exam questions often give you test results, like a prime checker that wrongly accepts 9, and ask you to infer the bug.
Connect this key term to the AP exam workflow: review the course, practice questions, and check related study tools.
Review units, study guides, and course resources.
Check this vocabulary in multiple-choice context.
Apply key concepts in written AP responses.
Estimate the exam score you are working toward.
Review the highest-yield facts before practice.
Put the full course together before test day.