---
title: "AP CSP 3.6: Conditionals, IF, and IF-ELSE Statements"
description: "Review AP Computer Science Principles Topic 3.6, including conditionals, IF statements, IF-ELSE statements, Boolean conditions, selection, flow of control, and tracing conditional logic."
canonical: "https://fiveable.me/ap-comp-sci-p/unit-3/conditionals/study-guide/JAgsZEPFqWJchRBqrX1O"
type: "study-guide"
subject: "AP Computer Science Principles"
unit: "Unit 3 – Algorithms & Programming Fundamentals"
lastUpdated: "2026-06-08"
---

# AP CSP 3.6: Conditionals, IF, and IF-ELSE Statements

## Summary

Review AP Computer Science Principles Topic 3.6, including conditionals, IF statements, IF-ELSE statements, Boolean conditions, selection, flow of control, and tracing conditional logic.

## Guide

## TLDR
Conditionals (also called if-statements) let a program choose which code to run based on whether a Boolean [condition](/ap-comp-sci-p/key-terms/condition "fv-autolink") is true or false. This is how programs make decisions, and on the [AP Computer Science Principles exam](/ap-comp-sci-p/ap-computer-science-principles-exam "fv-autolink") you need to both write them and trace what they output.

## Why This Matters for the AP Computer Science Principles Exam

[Selection](/ap-comp-sci-p/key-terms/selection "fv-autolink") is one of the three core building blocks of every [algorithm](/ap-comp-sci-p/key-terms/algorithm "fv-autolink"), 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](/ap-comp-sci-p/key-terms/pseudocode "fv-autolink"). 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](/ap-comp-sci-p/key-terms/create-performance-task "fv-autolink"), 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](/ap-comp-sci-p/key-terms/flow-of-control "fv-autolink") based on a [Boolean expression](/ap-comp-sci-p/unit-3/boolean-expressions/study-guide/LkLTi80KQM04AnmNBxCq "fv-autolink").
- `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 `ELSE` block runs only when the matching `IF` condition 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:

```
IF (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:

```
strawberries_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:

```
IF (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:

```
strawberries_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](/ap-comp-sci-p/key-terms/variable "fv-autolink") 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 no `ELSE`, 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 `ELSE` means nothing in that conditional runs.
- An `ELSE` block is not optional extra code that always runs. It runs only when the matching `IF` condition 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

- [3.1 Variables and Assignments](/ap-comp-sci-p/unit-3/variables-assignments/study-guide/vtJhAf5XFOkm1uHNDMvh)
- [Big Idea 3: Algorithms and Programming](/ap-comp-sci-p/unit-3/review/study-guide/eOWMqAJUdtnmttaCSlis)
- [3.12 Calling Procedures](/ap-comp-sci-p/unit-3/calling-procedures/study-guide/lwdr3yhVOtUJZhAmJ5cu)
- [3.18 Undecidable Problems](/ap-comp-sci-p/unit-3/undecidable-problems/study-guide/q0SSR2ddayx397Hy6ztA)
- [3.17 Algorithmic Efficiency](/ap-comp-sci-p/unit-3/algorithmic-efficiency/study-guide/jGSWIqW49BtrQ8dqCWFd)
- [3.2 Data Abstraction](/ap-comp-sci-p/unit-3/data-abstraction/study-guide/kMMTClSiHohfiaHMGFFE)

## Vocabulary

- **Boolean expression**: An expression that evaluates to either true or false, often composed of conditions combined with logical operators.
- **ELSE**: A keyword used in conditional statements to specify a block of code that executes when the Boolean condition is false.
- **algorithm**: Step-by-step procedures or sets of rules designed to solve a problem or accomplish a task.
- **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.
- **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.

## FAQs

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

## Structured Data

```json
{"@context":"https://schema.org","@type":"FAQPage","inLanguage":"en","mainEntity":[{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-p/unit-3/conditionals/study-guide/JAgsZEPFqWJchRBqrX1O#what-are-conditionals-in-ap-csp","name":"What are conditionals in AP CSP?","acceptedAnswer":{"@type":"Answer","text":"Conditionals are selection statements that let an algorithm choose which block of code runs based on whether a Boolean condition is true or false."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-p/unit-3/conditionals/study-guide/JAgsZEPFqWJchRBqrX1O#what-does-an-if-statement-do","name":"What does an IF statement do?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-p/unit-3/conditionals/study-guide/JAgsZEPFqWJchRBqrX1O#what-does-an-if-else-statement-do","name":"What does an IF-ELSE statement do?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-p/unit-3/conditionals/study-guide/JAgsZEPFqWJchRBqrX1O#what-is-a-boolean-condition","name":"What is a Boolean condition?","acceptedAnswer":{"@type":"Answer","text":"A Boolean condition is an expression that evaluates to true or false, such as score >= 90 or name = \"Alex\" in AP CSP pseudocode contexts."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-p/unit-3/conditionals/study-guide/JAgsZEPFqWJchRBqrX1O#how-do-you-trace-conditional-logic","name":"How do you trace conditional logic?","acceptedAnswer":{"@type":"Answer","text":"Evaluate the condition using the current variable values, run the matching block, update any changed variables, and then continue to the next statement."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-p/unit-3/conditionals/study-guide/JAgsZEPFqWJchRBqrX1O#how-are-conditionals-used-on-the-ap-csp-exam","name":"How are conditionals used on the AP CSP exam?","acceptedAnswer":{"@type":"Answer","text":"Conditionals appear in algorithm tracing, pseudocode reading, and Create task explanations where you describe how selection changes program behavior."}}]}
```
