PrepGo

AP Computer Science A Flashcards: if Statements

Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026

Review key ideas with interactive flashcards. This set includes 10 cards to help you master important concepts.

How do selection statements affect the flow of code execution?
Selection statements alter the default sequential execution of code, allowing different segments of code to be run or skipped depending on a condition.
Card 1 of 10

All Flashcards (10)

How do selection statements affect the flow of code execution?
Selection statements alter the default sequential execution of code, allowing different segments of code to be run or skipped depending on a condition.
In a two-way selection, what determines which segment of code is executed?
The result of the Boolean expression determines execution; one segment runs if the expression is true, and the other segment runs if the expression is false.
What is the primary difference between a one-way and a two-way selection?
A one-way selection executes a block of code only if a condition is true, whereas a two-way selection executes one of two different blocks of code depending on whether the condition is true or false.
When is it appropriate to use a one-way selection (`if`) instead of a two-way selection (`if-else`)?
A one-way selection is appropriate when an action should only be taken if a condition is true, and no alternative action is needed if the condition is false.
A program needs to print "Access Granted" if a password is correct and "Access Denied" if it is not. Which selection statement should be used?
A two-way selection (`if-else` statement) should be used because there are two distinct segments of code to execute based on the condition's outcome.
If an `if` statement's Boolean expression is false, what is the result of this logical process?
If the Boolean expression is false, the code within the `if` statement's body is skipped, and the program's sequential execution continues from the statement following the `if` block.
Under what condition is the body of a one-way `if` statement executed?
The body of a one-way `if` statement is executed only when its associated Boolean expression evaluates to true.
What is a one-way selection statement?
A one-way selection, or `if` statement, is a control structure used to execute a specific segment of code only when a certain Boolean expression is true.
What is a two-way selection statement?
A two-way selection, or `if-else` statement, is used when there are two different segments of code to execute: one for when a Boolean expression is true, and another for when it is false.
What is the function of selection statements in programming?
Selection statements are used to represent branching logical processes and change the sequential execution of statements based on certain conditions.