AP Computer Science Principles Flashcards: Nested Conditionals
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.
What are nested conditional statements?
Nested conditional statements consist of conditional statements that are placed within other conditional statements.
Card 1 of 10
All Flashcards (10)
What are nested conditional statements?
Nested conditional statements consist of conditional statements that are placed within other conditional statements.
Given `score = 75`, what is the result of this code? `if (score > 90) { print("A"); } else { if (score > 80) { print("B"); } else { print("C"); } }`
The result is "C". The first condition (75 > 90) is false, and the nested condition (75 > 80) is also false, leading to the final else block.
What is meant by "nested selection"?
Nested selection refers to the programming structure where a selection statement (like an if-statement) is contained inside another selection statement.
Given `x = 10`, what is the result of the following nested conditional statement? `if (x > 5) { if (x > 15) { print("A"); } else { print("B"); } }`
The result is "B". The outer condition (10 > 5) is true, but the inner condition (10 > 15) is false, so the inner else block is executed.
Given `age = 20`, what is the result of this statement? `if (age < 18) { print("Minor"); } else { if (age > 65) { print("Senior"); } else { print("Adult"); } }`
The result is "Adult". The outer condition (20 < 18) is false, and the first inner condition (20 > 65) is also false, so the inner else block executes.
When is the inner condition of a nested conditional statement evaluated?
The inner conditional statement is only evaluated if the condition of the outer conditional statement it is nested within is true.
How does the structure of a nested conditional statement differ from a simple conditional statement?
A nested conditional contains at least one conditional statement within the code block of another, creating a hierarchy of conditions.
Given `y = 5`, what is the result of this code? `if (y > 10) { if (y > 20) { print("High"); } } else { print("Low"); }`
The result is "Low". The first condition (5 > 10) is false, so the program immediately executes the outer else block without checking the inner condition.
What is the primary purpose of using nested selection?
Nested selection allows for checking a second, more specific condition after a primary, more general condition has been met.
What is a key skill needed to correctly interpret nested conditional statements?
A key skill is the ability to accurately trace the flow of control and determine the result by evaluating each condition in the correct sequence.