Concept Flow - Why conditional flow is needed
Start
Check Condition
Do A
End
The program checks a condition and chooses one path to follow: if true, it does one thing; if false, it does another.
<?php $age = 20; if ($age >= 18) { echo "Adult"; } else { echo "Minor"; } ?>
| Step | Variable $age | Condition ($age >= 18) | Branch Taken | Output |
|---|---|---|---|---|
| 1 | 20 | 20 >= 18 is True | Yes branch | "Adult" printed |
| 2 | - | - | End | Program ends |
| Variable | Start | After Condition Check | Final |
|---|---|---|---|
| $age | 20 | 20 | 20 |
Conditional flow lets programs choose actions based on conditions.
Syntax: if (condition) { do A } else { do B }
If condition is true, do A; else do B.
This helps programs react differently to different data.
Without it, programs would do the same thing always.