Concept Flow - Why conditional logic is needed
Start
Check Condition
Yes|No
Do Action A
End
The program checks a condition and chooses one action if true, another if false, then ends.
#include <iostream> int main() { int age = 20; if (age >= 18) { std::cout << "Adult"; } else { std::cout << "Minor"; } return 0; }
| Step | Variable 'age' | Condition 'age >= 18' | Branch Taken | Output |
|---|---|---|---|---|
| 1 | 20 | 20 >= 18 is True | If branch | "Adult" printed |
| 2 | - | - | End | - |
| Variable | Start | After Step 1 | Final |
|---|---|---|---|
| age | uninitialized | 20 | 20 |
Conditional logic lets programs choose actions based on conditions.
Syntax: if (condition) { action } else { other action }
If condition is true, first action runs; else, second runs.
This helps programs react differently to data or situations.