Concept Flow - If statement execution flow
Start
Evaluate condition
Execute if-block
Continue
Skip if-block
Continue
The program checks the condition. If true, it runs the code inside the if-block. If false, it skips it and continues.
<?php $age = 20; if ($age >= 18) { echo "Adult"; } ?>
| Step | Condition ($age >= 18) | Result | Branch Taken | Output |
|---|---|---|---|---|
| 1 | 20 >= 18 | True | Execute if-block | Adult |
| 2 | End of if statement | - | Continue | - |
| Variable | Start | After Step 1 | Final |
|---|---|---|---|
| $age | 20 | 20 | 20 |
if (condition) {
// code runs if condition is true
}
Checks condition once.
Runs block only if true.
Skips block if false.
Then continues program.if statement do in PHP?if (condition) { ... }. if condition { echo 'Yes'; } misses parentheses, C uses alternate syntax but missing parentheses, D uses square brackets which is invalid.$x = 10;
if ($x > 10) {
echo 'Greater';
} elseif ($x == 10) {
echo 'Equal';
} else {
echo 'Less';
}
if $a > 5 {
echo 'Big';
} else {
echo 'Small';
}if $a > 5 is missing parentheses.$score = 75;
if ($score >= 90) {
echo 'A';
} elseif ($score >= 80) {
echo 'B';
} elseif ($score >= 70) {
echo 'C';
} else {
echo 'F';
}
Pass the test and this pattern moves unknown