0
0
PHPprogramming~5 mins

Nested conditional execution in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ACheck multiple conditions inside each other
BRun code without any conditions
COnly check one condition at a time
DSkip all conditions
In nested if statements, when does the inner if run?
AAlways, no matter what
BOnly if the outer if condition is false
COnly if the outer if condition is true
DNever
What will this PHP code output? $score = 85; if ($score >= 90) { echo "A"; } else { if ($score >= 80) { echo "B"; } else { echo "C"; } }
AB
BA
CC
DNo output
Which symbol is used to start a conditional block in PHP?
A[
B(
C<
D{
What is the output if the outer if condition is false in nested conditionals?
AInner if runs anyway
BInner if does not run
CSyntax error
DProgram crashes
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.