---
title: "Loop Condition — AP Comp Sci A Definition & Exam Guide"
description: "A loop condition is the Boolean expression a while or for loop checks before each iteration. Get it wrong and you create infinite loops or off-by-one errors on the AP CSA exam."
canonical: "https://fiveable.me/ap-comp-sci-a/key-terms/loop-condition"
type: "key-term"
subject: "AP Computer Science A"
---

# Loop Condition — AP Comp Sci A Definition & Exam Guide

## Definition

A loop condition is the Boolean expression a loop evaluates before each iteration to decide whether to run the body again; the loop continues while the condition is true and stops the moment it evaluates to false.

## What It Is

A loop condition is the [Boolean expression](/ap-comp-sci-a/unit-2/for-loops/study-guide/DJuLxKz6SiSAX2cEVmCt "fv-autolink") sitting in the parentheses of a `while` or `for` [loop](/ap-comp-sci-a/key-terms/loop "fv-autolink"). Before every single iteration, Java evaluates it. True means run the body one more time. False means skip the body and jump to the code after the loop.

Here's the mental [shift](/ap-comp-sci-a/unit-4/developing-algorithms-using-arraylists/study-guide/MKbteieYvLOpWIwfqiND "fv-autolink") that makes loops click. The condition is a **continuation condition**, not a stopping condition. `while (count < 10)` doesn't mean "stop at 10." It means "keep going as long as count is less than 10." Reading it backwards is the source of most loop bugs. Something inside the loop body (or the update part of a for loop, like `i++`) has to eventually push the condition to false, or the loop never ends. The condition is only checked at the top of each pass, so if it's false the very first time, the body runs zero times. That zero-iteration case shows up constantly in AP questions.

## Why It Matters

Loop conditions are the heart of [Unit 4](/ap-comp-sci-a/unit-4 "fv-autolink") (Iteration) in AP CSA, where you write and trace `while` and `for` loops. Almost every classic Unit 4 skill runs through the condition. Counting how many times a loop executes means asking "for which values is this condition true?" Spotting an [infinite loop](/ap-comp-sci-a/key-terms/infinite-loop "fv-autolink") means asking "does anything ever make this condition false?" Off-by-one errors are almost always a `<` vs `<=` mistake in the condition.

It doesn't stay in Unit 4, either. [Array](/ap-comp-sci-a/unit-4/array-creation-and-access/study-guide/umTe6NA38OqZOhMZjFWi "fv-autolink") and ArrayList traversals in Units 6-7 depend on conditions like `i < arr.length` (use `<=` and you get an ArrayIndexOutOfBoundsException). 2D array nested loops in Unit 8 stack two conditions on top of each other. Every FRQ that processes a list, string, or grid lives or dies by a correctly written loop condition.

## Connections

### [Infinite Loop (Unit 4)](/ap-comp-sci-a/key-terms/infinite-loop)

An infinite loop is what happens when the loop condition never becomes false, usually because the [loop body](/ap-comp-sci-a/key-terms/loop-body "fv-autolink") forgot to update the variable the condition depends on. On the exam, "which change causes an infinite loop?" is really a question about the condition.

### Iteration (Unit 4)

Iteration is the act of repeating the loop body, and the loop condition is the gatekeeper that decides how many iterations happen. [Tracing](/ap-comp-sci-a/key-terms/tracing "fv-autolink") iteration questions means checking the condition before each pass, not after.

### Fixed Number of Repetitions (Unit 4)

A for loop like `for (int i = 0; i < n; i++)` produces exactly n repetitions because the condition `i < n` is true for exactly n values of i. Counting executions is just counting the true cases of the condition.

### [Equals Method (Unit 2)](/ap-comp-sci-a/key-terms/equals-method)

When a loop condition compares Strings, you need `.equals()` instead of `==`, because `==` compares references, not contents. A condition like `while (!word.equals("stop"))` is correct; `while (word != "stop")` is a classic trap answer.

## On the AP Exam

Loop conditions show up heavily in multiple choice as code-tracing questions. You'll be asked how many times a loop body executes, what a variable equals after the loop ends, or which version of a condition causes an infinite loop or an off-by-one error. The reliable move is to test the boundary values: the first value of the loop variable, the last value where the condition is true, and the value that finally makes it false.

On the FRQs, you write the conditions yourself. FRQ 1 (Methods and Control Structures) and FRQ 3-4 (array/ArrayList and 2D array questions) almost always require a traversal loop, and the rubric expects a condition that hits every needed element without going out of bounds. Writing `i <= arr.length` instead of `i < arr.length` costs points and crashes the code. No released FRQ asks you to define "loop condition," but nearly every one makes you write a correct one.

## Loop Condition vs If-statement condition

Both are Boolean expressions in parentheses, but an if condition is checked exactly once, while a loop condition is re-checked before every iteration. An if statement asks "should I do this?" one time. A loop condition asks "should I do this again?" over and over until the answer is no. That repetition is why a loop condition needs something in the body to eventually change its outcome, and an if condition doesn't.

## Key Takeaways

- A loop condition is a Boolean expression checked before each iteration; the loop runs while it is true and exits as soon as it is false.
- It's a continuation condition, not a stop condition, so while (x < 10) means 'keep going while less than 10,' not 'stop at 10.'
- If the condition is false on the very first check, the loop body executes zero times, which is a favorite multiple-choice trap.
- If nothing inside the loop ever makes the condition false, you get an infinite loop.
- For array traversals, the safe condition is i < arr.length; using <= goes one index too far and throws an ArrayIndexOutOfBoundsException.
- When the condition compares Strings, use .equals() instead of ==, because == compares references rather than contents.

## FAQs

### What is a loop condition in AP Computer Science A?

It's the Boolean expression in the parentheses of a while or for loop that Java evaluates before each iteration. True runs the body again; false ends the loop. It's the core mechanic of Unit 4 (Iteration).

### Does the loop body run at least once if the condition is false?

No. For the while and for loops tested on the AP exam, the condition is checked before the first iteration, so a false condition means the body runs zero times. Java's do-while loop runs once before checking, but do-while is not part of the AP CSA exam.

### Is the loop condition checked after every iteration or before?

Before. The loop evaluates the condition at the top of each pass. The body might even change the variable mid-iteration, but the loop won't exit until it loops back up and re-checks the condition.

### How is a loop condition different from an if condition?

An if condition is evaluated once and the program moves on. A loop condition is evaluated repeatedly, before every iteration, until it becomes false. That's why loops need an update statement (like i++) and if statements don't.

### Why does i <= arr.length cause an error in a loop condition?

Array indexes run from 0 to arr.length - 1, so when i equals arr.length the condition is still true and arr[i] throws an ArrayIndexOutOfBoundsException. The correct condition for a full traversal is i < arr.length.

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/loop-condition#resource","name":"Loop Condition — AP Comp Sci A Definition & Exam Guide","url":"https://fiveable.me/ap-comp-sci-a/key-terms/loop-condition","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-a/key-terms/loop-condition#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"dateModified":"2026-06-12T23:22:04.937Z","isPartOf":{"@type":"Collection","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"},"publisher":{"@type":"Organization","name":"Fiveable","url":"https://fiveable.me"}},{"@type":"DefinedTerm","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/loop-condition#term","name":"Loop Condition","description":"A loop condition is the Boolean expression a loop evaluates before each iteration to decide whether to run the body again; the loop continues while the condition is true and stops the moment it evaluates to false.","url":"https://fiveable.me/ap-comp-sci-a/key-terms/loop-condition","inDefinedTermSet":{"@type":"DefinedTermSet","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"}},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is a loop condition in AP Computer Science A?","acceptedAnswer":{"@type":"Answer","text":"It's the Boolean expression in the parentheses of a while or for loop that Java evaluates before each iteration. True runs the body again; false ends the loop. It's the core mechanic of Unit 4 (Iteration)."}},{"@type":"Question","name":"Does the loop body run at least once if the condition is false?","acceptedAnswer":{"@type":"Answer","text":"No. For the while and for loops tested on the AP exam, the condition is checked before the first iteration, so a false condition means the body runs zero times. Java's do-while loop runs once before checking, but do-while is not part of the AP CSA exam."}},{"@type":"Question","name":"Is the loop condition checked after every iteration or before?","acceptedAnswer":{"@type":"Answer","text":"Before. The loop evaluates the condition at the top of each pass. The body might even change the variable mid-iteration, but the loop won't exit until it loops back up and re-checks the condition."}},{"@type":"Question","name":"How is a loop condition different from an if condition?","acceptedAnswer":{"@type":"Answer","text":"An if condition is evaluated once and the program moves on. A loop condition is evaluated repeatedly, before every iteration, until it becomes false. That's why loops need an update statement (like i++) and if statements don't."}},{"@type":"Question","name":"Why does i <= arr.length cause an error in a loop condition?","acceptedAnswer":{"@type":"Answer","text":"Array indexes run from 0 to arr.length - 1, so when i equals arr.length the condition is still true and arr[i] throws an ArrayIndexOutOfBoundsException. The correct condition for a full traversal is i < arr.length."}}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"AP Computer Science A","item":"https://fiveable.me/ap-comp-sci-a"},{"@type":"ListItem","position":2,"name":"Key Terms","item":"https://fiveable.me/ap-comp-sci-a/key-terms"},{"@type":"ListItem","position":3,"name":"Loop Condition"}]}]}
```
