Conditionals

David Foster
5 min read
Listen to this study note
Study Guide Overview
This study guide covers control flow in programming, focusing on selection with if
statements, else
statements, and Boolean expressions. It explains the structure and logic of these statements in pseudocode and Python, provides practice questions (MCQs and FRQs) involving conditional logic, and offers final exam tips emphasizing the importance of these concepts, indentation, and combining them with other programming elements like loops and data structures.
#AP Computer Science Principles: The Night Before
Hey there! Let's get you totally prepped for the AP CSP exam. We're going to make sure everything clicks, so you can walk in feeling confident. Let's dive in!
#đ Control Flow: Sequencing, Selection, and Iteration
#Selection: Making Decisions with if
Statements
We're diving into selection, which is all about making choices in your code using conditional statements (aka if
statements). Think of it like a choose-your-own-adventure book, but for computers! đšī¸
#What are if
Statements?
if
statements allow your program to execute different code blocks based on whether a condition istrue
orfalse
.- They use Boolean expressions (expressions that evaluate to
true
orfalse
) to decide which path to take.
if
statements are fundamental for creating dynamic and responsive programs. They're how your code makes decisions!
#Basic if
Statement Structure
Here's how a basic if
statement looks in pseudocode:

How are we doing?
Give us your feedback and let us know how we can improve