Concept Flow - If–else statement
Start
Evaluate condition
Execute if-block
End
Execute else-block
End
The program checks a condition. If true, it runs the 'if' part; if false, it runs the 'else' part, then ends.
#include <iostream> using namespace std; int main() { int x = 10; if (x > 5) { cout << "Big"; } else { cout << "Small"; } return 0; }
| Step | Condition (x > 5) | Result | Branch Taken | Output |
|---|---|---|---|---|
| 1 | 10 > 5 | true | if-block | "Big" |
| 2 | - | - | End | - |
| Variable | Start | After Step 1 | Final |
|---|---|---|---|
| x | 10 | 10 | 10 |
if (condition) {
// code if true
} else {
// code if false
}
Checks condition once; runs if-block if true, else-block if false.