Recall & Review
beginner
What is nested conditional execution in C#?
It means putting one if or else if statement inside another if or else if statement to check multiple conditions step-by-step.
Click to reveal answer
beginner
How do you write a nested if statement in C#?
You write an if statement inside the block of another if or else if statement using curly braces { } to group the inner condition.
Click to reveal answer
beginner
Why use nested conditional execution?
To check more detailed conditions only if the first condition is true, like checking if a person is an adult, then checking if they have a driver’s license.
Click to reveal answer
beginner
What happens if the outer if condition is false in nested conditionals?
The inner if statements are skipped completely because the outer condition controls whether the inner code runs.
Click to reveal answer
beginner
Example: What will this code print?
if (age >= 18) {
if (hasLicense) {
Console.WriteLine("Can drive");
} else {
Console.WriteLine("No license");
}
} else {
Console.WriteLine("Too young");
}
If age is 20 and hasLicense is true, it prints "Can drive". If age is 20 and hasLicense is false, it prints "No license". If age is 16, it prints "Too young".
Click to reveal answer
What does nested conditional execution allow you to do?
✗ Incorrect
Nested conditionals let you check one condition inside another to make detailed decisions.
In C#, which symbol is used to group the inner if statement?
✗ Incorrect
Curly braces { } group the code blocks inside if statements.
If the outer if condition is false, what happens to the inner if?
✗ Incorrect
The inner if is skipped because the outer condition controls whether the inner code runs.
Which is a correct nested if structure in C#?
✗ Incorrect
You can put an if inside another if block correctly using braces.
What will this code print if age = 17?
if (age >= 18) {
Console.WriteLine("Adult");
} else {
Console.WriteLine("Minor");
}
✗ Incorrect
Since 17 is less than 18, the else block runs and prints "Minor".
Explain nested conditional execution and give a simple example in C#.
Think about checking one condition only if another is true.
You got /3 concepts.
Describe what happens when the outer condition in nested if statements is false.
Consider how the program decides which code to run.
You got /3 concepts.