---
title: "Logic Error — AP CSP Definition, Examples & Exam Guide"
description: "A logic error is a mistake that makes a program run but behave wrong. Learn how AP CSP tests it (EK CRD-2.I.1) and how it differs from syntax and run-time errors."
canonical: "https://fiveable.me/ap-comp-sci-p/key-terms/logic-error"
type: "key-term"
subject: "AP Computer Science Principles"
unit: "Unit 1"
---

# Logic Error — AP CSP Definition, Examples & Exam Guide

## Definition

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.

## What It Is

A logic error is a mistake in an [algorithm](/ap-comp-sci-p/key-terms/algorithm "fv-autolink") or [program](/ap-comp-sci-p/unit-1/program-function-purpose/study-guide/8hL8KatG4rAWTwZSglGB "fv-autolink") 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](/ap-comp-sci-p/unit-1/program-design-development/study-guide/SsouN8LrhRWiQ5hevIV6 "fv-autolink"). 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.

## Why It Matters

Logic errors live in **Topic 1.4 (Identifying and Correcting Errors)** in **[Unit 1](/ap-comp-sci-p/unit-1 "fv-autolink"): Creative Development**, under learning objective **[AP Comp Sci P](/ap-comp-sci-p "fv-autolink") 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.

## Connections

### [Syntax error (Unit 1)](/ap-comp-sci-p/key-terms/syntax-error)

[Syntax](/ap-comp-sci-p/key-terms/syntax "fv-autolink") 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)](/ap-comp-sci-p/key-terms/run-time-error)

A [run-time error](/ap-comp-sci-p/key-terms/run-time-error "fv-autolink") 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](/ap-comp-sci-p/key-terms/range "fv-autolink") (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)](/ap-comp-sci-p/key-terms/iterative-development-process)

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.

## On the AP Exam

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.

## logic error vs Syntax error

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.

## Key Takeaways

- 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).

## FAQs

### What is a logic error in AP Computer Science Principles?

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.

### Will a logic error cause a program to crash or show an error message?

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).

### What's the difference between a logic error and a syntax error?

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.

### How do you find a logic error in a program?

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.

### What are common logic error examples on the AP CSP exam?

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.

## Related Study Guides

- [1.4 Identifying and Correcting Errors](/ap-comp-sci-p/unit-1/identifying-correcting-errors/study-guide/pz4hGcBBElziI3R8cfnQ)

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-p/key-terms/logic-error#resource","name":"Logic Error — AP CSP Definition, Examples & Exam Guide","url":"https://fiveable.me/ap-comp-sci-p/key-terms/logic-error","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-p/key-terms/logic-error#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"dateModified":"2026-06-11T05:53:25.139Z","isPartOf":{"@type":"Collection","name":"AP Computer Science Principles Key Terms","url":"https://fiveable.me/ap-comp-sci-p/key-terms"},"publisher":{"@type":"Organization","name":"Fiveable","url":"https://fiveable.me"}},{"@type":"DefinedTerm","@id":"https://fiveable.me/ap-comp-sci-p/key-terms/logic-error#term","name":"logic error","description":"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.","url":"https://fiveable.me/ap-comp-sci-p/key-terms/logic-error","inDefinedTermSet":{"@type":"DefinedTermSet","name":"AP Computer Science Principles Key Terms","url":"https://fiveable.me/ap-comp-sci-p/key-terms"}},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is a logic error in AP Computer Science Principles?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","name":"Will a logic error cause a program to crash or show an error message?","acceptedAnswer":{"@type":"Answer","text":"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)."}},{"@type":"Question","name":"What's the difference between a logic error and a syntax error?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","name":"How do you find a logic error in a program?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","name":"What are common logic error examples on the AP CSP exam?","acceptedAnswer":{"@type":"Answer","text":"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."}}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"AP Computer Science Principles","item":"https://fiveable.me/ap-comp-sci-p"},{"@type":"ListItem","position":2,"name":"Key Terms","item":"https://fiveable.me/ap-comp-sci-p/key-terms"},{"@type":"ListItem","position":3,"name":"Unit 1","item":"https://fiveable.me/ap-comp-sci-p/unit-1"},{"@type":"ListItem","position":4,"name":"logic error"}]}]}
```
