Condition

In AP Computer Science Principles, a condition is a Boolean expression that evaluates to true or false and controls the flow of a program, deciding whether an IF statement's code block runs (selection) or when a REPEAT UNTIL loop stops (iteration).

Verified for the 2027 AP Computer Science Principles examLast updated June 2026

What is the condition?

A condition is any expression that evaluates to either true or false. That's it. The condition itself isn't the IF statement; it's the question inside the parentheses that the IF statement asks before deciding what to do. Per EK AAP-2.G.1, selection determines which parts of an algorithm run based on a condition being true or false, and EK AAP-2.H.1 says conditional statements change the sequential flow of control based on the value of a Boolean expression.

Conditions show up in two places on the exam reference sheet. In selection, IF (condition) runs its block only when the condition is true. In iteration, REPEAT UNTIL (condition) keeps looping until the condition becomes true (EK AAP-2.K.3). Conditions are usually built from comparison operators (like a < 15 or score = 100) and can be combined with logical operators (AND, OR, NOT) to ask more complex questions. Think of a condition as a yes/no question your program asks at a fork in the road.

Why the condition matters in AP Computer Science Principles

Conditions live in Unit 3 (Algorithms and Programming) and are the backbone of three topics at once: 3.6 Conditionals, 3.7 Nested Conditionals, and 3.8 Iteration. Learning objectives 3.6.A and 3.6.B require you to express and trace selection driven by a condition, 3.7.A extends that to conditions inside conditions, and 3.8.A/3.8.B flip the same idea into loops, where a stopping condition decides when repetition ends (EK AAP-2.K.1). If you can't read a condition correctly, you can't trace code, and tracing code is a huge chunk of the AP CSP multiple choice section. The same skill shows up in the Create Performance Task, where your program must include selection, which means it must include a condition you can explain.

How the condition connects across the course

Conditional Statements (Unit 3)

A conditional statement is the structure; the condition is the Boolean expression inside it. The IF statement is the fork in the road, and the condition is the sign telling you which way to go.

REPEAT UNTIL(condition) (Unit 3)

The exact same kind of Boolean expression that powers an IF statement also powers iteration. The twist is that REPEAT UNTIL runs while the condition is false and stops when it turns true. Get the condition wrong and you get an infinite loop (EK AAP-2.K.4).

Logical operators (Unit 3)

AND, OR, and NOT let you combine simple conditions into compound ones. One well-built compound condition like age >= 13 AND age <= 19 can sometimes replace an entire nested conditional.

Comparison operators (Unit 3)

Operators like <, >, =, and ≠ are how most conditions get built in the first place. Every comparison produces a true or false value, which is exactly what a condition needs to be.

Is the condition on the AP Computer Science Principles exam?

On the multiple choice section, conditions are mostly tested through code tracing. You get a snippet and a value, then determine which block runs. Fiveable practice questions do exactly this with nested conditionals, like tracing a = 12 through if (a < 15) { if (a > 10) ... } to figure out which return statement fires. Work outside-in: evaluate the outer condition first, then move inward only if it's true. Conditions also matter heavily on the Create Performance Task written response. The 2024 Written Response Q2 asked about the first conditional statement in your Personalized Project Reference, which means you need to explain what condition your program tests and why. The 2023 scoring criteria similarly rewarded clear explanations of how selection works in your code.

The condition vs Conditional statement

The condition is the Boolean expression (a < 15); the conditional statement is the whole IF structure that uses it. On the exam, when a question asks you to evaluate the condition, it wants true or false. When it asks for the result of the conditional statement, it wants to know which code block actually executed. Mixing these up costs points on trace questions.

Key things to remember about the condition

  • A condition is a Boolean expression that always evaluates to exactly true or false, never anything in between.

  • In selection, the code inside IF (condition) runs only when the condition is true; if it's false, an IF with no ELSE simply does nothing (EK AAP-2.H.2).

  • In iteration, REPEAT UNTIL (condition) loops while the condition is false and stops the moment it becomes true, which is the reverse of how an IF statement uses its condition.

  • If the stopping condition in a REPEAT UNTIL loop can never become true, the loop runs forever (an infinite loop).

  • When tracing nested conditionals, evaluate the outer condition first and only check inner conditions when the outer one is true.

  • Compound conditions built with AND, OR, and NOT can sometimes replace nested conditionals entirely.

Frequently asked questions about the condition

What is a condition in AP Computer Science Principles?

A condition is a Boolean expression that evaluates to true or false and controls program flow. It decides whether an IF statement's block runs and when a REPEAT UNTIL loop stops, covering EKs AAP-2.G.1, AAP-2.H.1, and AAP-2.K.3.

Is a condition the same thing as an if statement?

No. The condition is just the true/false expression like score > 50, while the if statement is the full structure that uses the condition to decide which code block executes. The exam can ask about either one separately.

Does a REPEAT UNTIL loop run while the condition is true?

No, and this is a classic trap. REPEAT UNTIL runs while the condition is FALSE and stops once it becomes true (EK AAP-2.K.3). That's the opposite of an IF statement, which executes its block when the condition is true.

What happens if a condition in an if statement is false?

With a plain IF, nothing happens and the program just moves on (EK AAP-2.H.2). With an IF-ELSE, the second block of statements runs instead (EK AAP-2.H.3).

How do I trace nested conditionals on the AP CSP exam?

Evaluate the outer condition first. If it's false, skip the entire nested block, including any inner IFs. If it's true, step inside and evaluate the inner condition the same way. For example, with a = 12, a < 15 is true, then a > 10 is true, so the result is the innermost true branch.