Recall & Review
beginner
What is nested conditional execution in PHP?
Nested conditional execution means placing one if or else statement inside another if or else statement to check multiple conditions step-by-step.
Click to reveal answer
beginner
How do you write a nested if statement in PHP?
You write an if statement inside another if or else block using curly braces { } to group the code that runs when conditions are true.
Click to reveal answer
beginner
Why use nested conditional execution?
It helps check multiple related conditions in order, like checking if a user is logged in, then if they have admin rights.
Click to reveal answer
beginner
What happens if the outer condition in a nested if is false?
The inner if statements inside it do not run at all because the outer condition controls whether the inner code is checked.
Click to reveal answer
beginner
Example: What will this PHP code output?
<?php
$age = 20;
if ($age >= 18) {
if ($age <= 65) {
echo "Adult";
} else {
echo "Senior";
}
} else {
echo "Minor";
}
?>The output will be "Adult" because 20 is greater than or equal to 18 and less than or equal to 65, so the inner if condition is true.
Click to reveal answer
What does nested conditional execution allow you to do in PHP?
✗ Incorrect
Nested conditional execution lets you check one condition inside another to handle complex decisions.
In nested if statements, when does the inner if run?
✗ Incorrect
The inner if runs only if the outer if condition is true, because it is inside that block.
What will this PHP code output?
$score = 85;
if ($score >= 90) {
echo "A";
} else {
if ($score >= 80) {
echo "B";
} else {
echo "C";
}
}
✗ Incorrect
Since 85 is not >= 90, the outer else runs. Then the inner if checks if 85 >= 80, which is true, so it outputs "B".
Which symbol is used to start a conditional block in PHP?
✗ Incorrect
Curly braces { } are used to group code blocks for conditions in PHP.
What is the output if the outer if condition is false in nested conditionals?
✗ Incorrect
If the outer if condition is false, the inner if inside it does not run.
Explain how nested conditional execution works in PHP with an example.
Think about checking one condition inside another to decide what code runs.
You got /4 concepts.
Describe why nested conditionals are useful in programming decisions.
Consider how you decide things in steps, like checking if someone is logged in, then if they are admin.
You got /4 concepts.