Recall & Review
beginner
What is a nested conditional statement in C++?
A nested conditional statement is an if or else if statement placed inside another if or else block. It allows checking multiple conditions step-by-step.
Click to reveal answer
beginner
How do nested if statements work?
The outer if condition is checked first. If it is true, then the inner if condition is checked. This continues for deeper levels, allowing detailed decision paths.
Click to reveal answer
beginner
Why use nested conditional statements?
They help handle complex decisions where one condition depends on another. For example, checking age and then checking if a person has a ticket.
Click to reveal answer
beginner
What happens if the outer if condition is false in nested ifs?
If the outer if condition is false, the inner if statements inside it are skipped entirely.
Click to reveal answer
beginner
Write a simple nested if example in C++ to check if a number is positive and even.
if (number > 0) {
if (number % 2 == 0) {
// number is positive and even
}
}
Click to reveal answer
What does a nested if statement allow you to do?
✗ Incorrect
Nested if statements let you check one condition inside another, allowing detailed decision making.
If the outer if condition is false, what happens to the inner if?
✗ Incorrect
Inner if statements inside a false outer if block are skipped.
Which symbol is used for the else part of an if statement?
✗ Incorrect
In C++, the keyword 'else' is used for the alternative block if the if condition is false.
What is the output if number = 4 in this code?
if (number > 0) {
if (number % 2 == 0) {
cout << "Even positive";
}
}
✗ Incorrect
4 is greater than 0 and even, so the inner if runs and prints 'Even positive'.
Can nested if statements be more than two levels deep?
✗ Incorrect
You can nest if statements as many levels as needed, but readability may suffer.
Explain how nested conditional statements work in C++ with an example.
Think about checking one condition inside another.
You got /4 concepts.
Why might you choose to use nested if statements instead of multiple separate if statements?
Consider when one condition depends on another.
You got /4 concepts.