TLDR
Conditionals (also called if-statements) let a program choose which code to run based on whether a Boolean condition is true or false. This is how programs make decisions, and on the AP Computer Science Principles exam you need to both write them and trace what they output.

Why This Matters for the AP Computer Science Principles Exam
Selection is one of the three core building blocks of every algorithm, along with sequencing and iteration. Conditionals are how you put decision-making into a program, so they show up across the Algorithms and Programming material, which is the largest part of the exam.
On the multiple-choice section, you can expect to trace conditional code and determine its result, decide whether a block of statements runs, and read selection logic written in the exam reference sheet pseudocode. You also may need to express selection without using a specific programming language, such as in plain steps or pseudocode. In the Create performance task, conditionals are a natural way to show decision logic in your own program and explain how it works in your written responses.
Key Takeaways
- Selection runs different parts of an algorithm depending on whether a condition evaluates to true or false.
- A conditional changes the normal top-to-bottom flow of control based on a Boolean expression.
IF (condition) { <block> }runs the block only when the condition is true; if it is false, nothing in that block runs.IF (condition) { <first block> } ELSE { <second block> }runs the first block when the condition is true and the second block when it is false.- An
ELSEblock runs only when the matchingIFcondition is false. - You can describe selection in plain language or pseudocode, not just in a specific programming language.
Selection and Flow of Control
A program normally runs statements one after another, top to bottom. That is sequencing. Selection lets you break out of that straight line and pick which statements run based on a condition.
A condition is a Boolean expression, meaning it evaluates to either true or false. The program checks that condition, then decides which block of statements to execute. This is what lets a program respond differently to different inputs.
If Statement
An if-statement runs a block of code only when its condition is true. Here is the format using the AP exam reference sheet pseudocode:
</>CodeIF (condition) { <block of statements> }
If the condition evaluates to true, the block of statements runs. If the condition is false, the program skips that block and moves on to whatever comes next. No action is taken in that case.
Here is the same idea in Python:
</>Codestrawberries_in_fridge = 7 if strawberries_in_fridge >= 7: print("You can make strawberry shortcake!")
The condition here is the Boolean expression strawberries_in_fridge >= 7. Since strawberries_in_fridge is 7, the condition is true, so the print statement runs.
If strawberries_in_fridge had been less than 7, the condition would be false. The program would skip the print statement and continue with the rest of the code.
If-Else Statement
An if-statement can include an ELSE block that says what to do when the condition is false. Here is the pseudocode format:
</>CodeIF (condition) { <first block of statements> } ELSE { <second block of statements> }
If the condition is true, the first block runs. Otherwise, the second block runs. Exactly one of the two blocks runs every time.
Here it is in Python:
</>Codestrawberries_in_fridge = 7 if strawberries_in_fridge >= 10: print("You can make strawberry shortcake!") else: print("Sorry, no shortcake for you!")
The condition strawberries_in_fridge >= 10 is false because 7 is less than 10. Since the if condition is false, the program runs the else block and prints "Sorry, no shortcake for you!"
How to Use This on the AP Computer Science Principles Exam
MCQ and Code Tracing
When you see a conditional in a question, work through it in order:
- Identify the condition and evaluate it as true or false using the current variable values.
- If it is true, run the if block. If it is false and there is an
ELSE, run the else block. If it is false and there is noELSE, run nothing in that conditional. - Track any variable changes inside the block, then continue to the next statement.
Writing and Expressing Selection
You may be asked to write a conditional or express selection without a specific language. Practice describing the decision in plain steps first ("if the value is at least 7, do this, otherwise do that"), then translate it into the pseudocode or your chosen language. Make sure your condition is a Boolean expression that actually evaluates to true or false.
Common Trap
Read carefully whether a condition uses >= versus >, or = versus a comparison. A small difference like 7 versus 10 in a condition changes which block runs, and questions are designed to catch that.
Common Misconceptions
- An if-statement does not always run its block. The block runs only when the condition is true. A false condition with no
ELSEmeans nothing in that conditional runs. - An
ELSEblock is not optional extra code that always runs. It runs only when the matchingIFcondition is false. - With an if-else, both blocks never run on the same pass. Exactly one of them runs each time.
- The condition is not a command that does something on its own. It is a Boolean expression that the program evaluates to true or false to decide what to run.
- Selection is not the same as repetition. A conditional chooses whether a block runs, while iteration repeats a block. Those are different building blocks.
Related AP Computer Science Principles Guides
Vocabulary
The following words are mentioned explicitly in the College Board Course and Exam Description for this topic.Term | Definition |
|---|---|
algorithm | Step-by-step procedures or sets of rules designed to solve a problem or accomplish a task. |
Boolean expression | An expression that evaluates to either true or false, often composed of conditions combined with logical operators. |
condition | A statement that evaluates to either true or false, used to determine the flow of execution in a selection structure. |
conditional statement | A programming construct that executes different code blocks based on whether a specified condition is true or false. |
ELSE | A keyword used in conditional statements to specify a block of code that executes when the Boolean condition is false. |
if-statements | A type of conditional statement that executes a block of code only if a specified Boolean condition is true. |
selection | A control structure that determines which parts of an algorithm are executed based on whether a condition is true or false. |
sequential flow of control | The order in which statements are executed in a program; conditional statements can alter this flow by executing different code based on conditions. |
Frequently Asked Questions
What are conditionals in AP CSP?
Conditionals are selection statements that let an algorithm choose which block of code runs based on whether a Boolean condition is true or false.
What does an IF statement do?
An IF statement runs its block only when the condition is true. If the condition is false and there is no ELSE, the block is skipped.
What does an IF-ELSE statement do?
An IF-ELSE statement runs the first block when the condition is true and the second block when the condition is false. Exactly one block runs.
What is a Boolean condition?
A Boolean condition is an expression that evaluates to true or false, such as score >= 90 or name = "Alex" in AP CSP pseudocode contexts.
How do you trace conditional logic?
Evaluate the condition using the current variable values, run the matching block, update any changed variables, and then continue to the next statement.
How are conditionals used on the AP CSP exam?
Conditionals appear in algorithm tracing, pseudocode reading, and Create task explanations where you describe how selection changes program behavior.