6m left·0%
Reading Time: 6 min
Last Updated: March 6, 2026
Main Ideas: 5
Reading Time: 6 min
Last Updated: March 6, 2026
Main Ideas: 5

Topic 3.6 Notes – Conditionals

Verified for 2027 AP® Computer Science Principles Exam
Read aloud
This is how a program makes decisions. Instead of running every line in order, the program checks a condition and chooses which code to execute based on whether that condition is true or false.

What Selection Does in an Algorithm

Up to now, you’ve seen that programs normally run sequentially. One statement runs, then the next, then the next.

Selection changes that flow.

A conditional statement:

  • Checks a Boolean expression (true/false)
  • Decides which block of code runs
  • Skips the other block

So the flow becomes something like this:

Study guide illustration

Flowchart of an if-else conditional

The diamond labeled If Condition is the decision point. Only one path, either the True branch or the False branch, is taken before the program continues.

This connects directly to the big idea of Unit 3: how statements are combined determines the result. If you change the condition, you change which path runs. That changes the output.

Boolean Conditions Drive the Decision

Everything in a conditional depends on a Boolean expression.

A Boolean expression:

  • Evaluates to true or false
  • Often compares values
    • score ≥ 70
    • age = 18
    • temperature < 0
  • Can combine conditions using:
    • AND → both must be true
    • OR → at least one must be true
    • NOT → reverses the value

Example:

(age ≥ 16) AND (hasLicense = true)

This is only true if both parts are true.

Where students lose points is mis-evaluating the Boolean. If you get the condition wrong, the entire execution path is wrong. On multiple-choice questions, they love giving slightly tricky conditions like:

x > 5 AND x < 10

If x ← 5, that condition is false. 5 is not greater than 5.

Be precise.

The Two Forms of Conditional Statements

The AP exam reference sheet gives you two official formats. You need to recognize and write both exactly like this.

IF (condition)

IF (condition)
{
   <block of statements>
}

What happens:

  • If condition is true → run the block.
  • If condition is false → skip it.
  • Execution continues after the block.

So this form gives you zero or one block executed.

Example:

IF (score ≥ 90)
{
   DISPLAY("A")
}

If the score is 85, nothing displays. The program just moves on.

IF (condition) ELSE

IF (condition)
{
   <first block>
}
ELSE
{
   <second block>
}

What happens:

  • If condition is true → run first block.
  • Otherwise → run second block.
  • Exactly one block runs. Never both.

Here’s how they compare:

Feature IF IF-ELSE
If condition is true Block runs First block runs
If condition is false Nothing happens Second block runs
Possible paths 0 or 1 block Exactly 1 block

A common mistake is thinking both blocks somehow run. They don’t. The condition forces a choice.

Tracing Conditional Statements

Being able to determine the result of a conditional is heavily tested.

When tracing:

  1. Identify current variable values.
  2. Evaluate the Boolean expression carefully.
  3. Decide true or false.
  4. Execute only that block.
  5. Continue sequentially.

Example:

x ← 4
IF (x MOD 2 = 0)
{
   x ← x + 3
}
ELSE
{
   x ← x - 1
}
DISPLAY(x)
  • 4 MOD 2 = 0 → true
  • First block runs → x ← 7
  • Output is 7

Students often:

  • Forget that = means equality comparison (not assignment).
  • Change a variable from a block that never executed.
  • Forget that earlier conditionals may change values used later.

Slow down and follow the flow.

Expressing Selection Without Code

You are also expected to describe an algorithm in plain language that uses selection.

Your description must clearly include:

  • The condition
  • What happens if it’s true
  • What happens if it’s false (if applicable)

Example in words:

If the user enters the correct PIN, display “Access Granted.” Otherwise, display “Access Denied.”

That’s a complete conditional. It shows the decision and both outcomes.

On written responses, vague wording like “check the PIN and respond accordingly” is not enough. You must clearly state what happens in each case.

Think in this structure:

If (condition is true) → do this
Otherwise → do that

If someone else could turn your sentence directly into an IF-ELSE block, you’ve done it right.

Key Takeaways

Selection changes program flow by choosing between paths based on a Boolean condition.
A Boolean expression must evaluate completely to true or false before a decision is made.
In IF-ELSE, exactly one block executes, never both.
In a plain IF, nothing happens when the condition is false.
Always trace variable values step by step before deciding which block runs.
When describing conditionals in words, clearly state the condition and both possible outcomes.

AP® is a trademark registered by the College Board, which is not affiliated with, and does not endorse this website.

Notes

1 credit used · 5/5 remaining