Concept Flow - If statement
Start
Evaluate condition
Execute if-block
Continue
Skip if-block
Continue
The program checks a condition. If true, it runs the code inside the if-block; if false, it skips it and continues.
#include <iostream> using namespace std; int main() { int x = 5; if (x > 3) { cout << "x is greater than 3" << endl; } cout << "Done" << endl; return 0; }
| Step | Condition (x > 3) | Result | Branch Taken | Output |
|---|---|---|---|---|
| 1 | 5 > 3 | True | Execute if-block | x is greater than 3 |
| 2 | N/A | N/A | Continue after if | Done |
| Variable | Start | After Step 1 | After Step 2 |
|---|---|---|---|
| x | 5 | 5 | 5 |
If statement syntax:
if (condition) {
// code runs if condition true
}
Checks condition once.
Runs block only if true.
Skips block if false.
Then continues program.