PrepGo

AP Computer Science Principles Practice Quiz: Conditionals

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

Test your understanding with short quizzes. This quiz has 15 questions to check your progress.

Question 1 of 15

According to the provided content, what is the primary function of 'selection' in an algorithm?

All Questions (15)

According to the provided content, what is the primary function of 'selection' in an algorithm?

A) To repeat a set of instructions multiple times.

B) To store data for later use.

C) To determine which parts of an algorithm are executed based on a condition.

D) To break down a large problem into smaller, manageable parts.

Correct Answer: C

The content explicitly states that 'Selection determines which parts of an algorithm are executed based on a condition being true or false.'

What is another name for 'if-statements' as mentioned in the text?

A) Sequential statements

B) Boolean expressions

C) Execution blocks

D) Conditional statements

Correct Answer: D

The text states, 'Conditional statements, or "if-statements," affect the sequential flow of control...'

How do conditional statements alter the flow of an algorithm?

A) They always execute statements in a fixed, unchangeable order.

B) They affect the sequential flow of control by executing different statements based on a Boolean value.

C) They stop the algorithm's execution permanently.

D) They reverse the order of all subsequent statements.

Correct Answer: B

The content specifies that conditional statements 'affect the sequential flow of control by executing different statements based on the value of a Boolean expression.'

Consider the algorithm: 'If the temperature is below freezing, wear a heavy coat.' What happens if the temperature is NOT below freezing?

A) An error occurs.

B) A different, unspecified action is taken.

C) No action is taken based on this specific instruction.

D) The algorithm asks for the temperature again.

Correct Answer: C

This algorithm represents an IF(condition) structure. The content states that in this structure, 'a block of statements is executed if the condition is true, and no action is taken if the condition is false.'

Which structure provided on the exam reference sheet is best suited for an algorithm that must perform one action if a condition is met and a completely different action if it is not?

A) The IF structure

B) A Boolean expression

C) The IF-ELSE structure

D) Sequential flow of control

Correct Answer: C

The content describes the IF-ELSE structure as one where 'one block of statements is executed if the condition is true, and a second block is executed if the condition is false,' which perfectly matches the scenario.

An algorithm is described as: 'Check if a user is logged in. If they are, display the dashboard. If they are not, display the login page.' This logic is an example of expressing an algorithm that uses what concept?

A) Sequential execution only

B) Selection

C) A Boolean value

D) A programming language

Correct Answer: B

This is a natural language expression of an algorithm that uses selection. It chooses between two different paths (display dashboard vs. display login page) based on a condition (is the user logged in?).

In an `IF(condition)` statement, what type of value must the 'condition' evaluate to?

A) A number

B) A string of text

C) A Boolean (true or false)

D) A block of statements

Correct Answer: C

The content states that conditional statements execute based on 'the value of a Boolean expression,' which means the condition must resolve to either true or false.

What is the key difference between the `IF` and `IF-ELSE` structures as described in the content?

A) Only the IF-ELSE structure uses a Boolean condition.

B) The IF structure can execute multiple blocks of statements, while IF-ELSE can only execute one.

C) The IF-ELSE structure provides a specific block of code to execute when the condition is false, while the IF structure does not.

D) The IF structure is used for selection, while the IF-ELSE structure is not.

Correct Answer: C

The content defines the IF structure as taking 'no action' if the condition is false, whereas the IF-ELSE structure executes a 'second block' if the condition is false. This is the fundamental difference.

Consider the conditional statement: `IF (isFinished IS true) { DISPLAY "Complete" }`. What is the result if the value of `isFinished` is false?

A) The text "Complete" is displayed.

B) The program produces an error.

C) The program displays "Not Complete".

D) No action is taken by this statement.

Correct Answer: D

This is an `IF(condition)` structure. Since the condition `isFinished IS true` evaluates to false, the block of statements is skipped, and no action is taken, as per the definition from the exam reference sheet.

Consider the conditional statement: `IF (age < 18) { DISPLAY "Minor" } ELSE { DISPLAY "Adult" }`. If the variable `age` has a value of 25, what is the result?

A) Both "Minor" and "Adult" are displayed.

B) "Minor" is displayed.

C) "Adult" is displayed.

D) Neither message is displayed.

Correct Answer: C

The condition `age < 18` is evaluated. Since 25 is not less than 18, the condition is false. In an IF-ELSE structure, the second block (the ELSE block) is executed when the condition is false. Therefore, "Adult" is displayed.

The use of conditional statements to control which parts of an algorithm are run is known as:

A) Sequencing

B) Iteration

C) Selection

D) Abstraction

Correct Answer: C

The first and third points of the provided content directly define this process as 'selection'.

An algorithm needs to award a bonus only to employees who have sales greater than $10,000. Employees with sales of $10,000 or less receive nothing extra. Which is the most efficient and appropriate control structure to implement this logic?

A) An IF-ELSE structure to check for sales > 10000 and do nothing in the ELSE block.

B) An IF structure to check for sales > 10000.

C) A sequential structure that gives every employee a bonus and then takes it away if sales are too low.

D) An IF structure to check for sales <= 10000.

Correct Answer: B

The logic requires an action for one case (sales > 10000) and no action for the other. The IF structure is designed for exactly this, as it executes a block for a true condition and does nothing for a false one. Using an IF-ELSE with an empty ELSE block is less efficient.

Which of the following is the best natural language expression of an algorithm using an IF-ELSE structure?

A) First, wake up. Then, brush your teeth. Finally, eat breakfast.

B) If the alarm rings, get out of bed.

C) If it is a weekday, go to work; otherwise, stay home.

D) While you are hungry, continue eating.

Correct Answer: C

This option provides a condition (is it a weekday?), an action for when it's true (go to work), and an alternative action for when it's false (otherwise, stay home). This directly maps to the IF-ELSE structure.

The part of a conditional statement that evaluates to true or false, such as `x > 5` or `name = "Admin"`, is called a:

A) Block of statements

B) Selection structure

C) Sequential flow

D) Boolean expression

Correct Answer: D

The content states that conditional statements execute 'based on the value of a Boolean expression.' This expression is the condition itself which is evaluated.

A programmer writes an algorithm that checks if a number is even or odd and prints the result. Which control structure is required to accomplish this?

A) An IF structure, because it only needs to check if the number is even.

B) An IF-ELSE structure, because there are two distinct outcomes (even or odd) based on a single condition.

C) Two separate IF structures, one to check for even and one to check for odd.

D) Only sequential statements are needed.

Correct Answer: B

A number is either even or it is odd; there is no other possibility. This is a perfect use case for the IF-ELSE structure, where one action (print 'even') is taken if the condition is true, and a second action (print 'odd') is taken if it is false.