Concept Flow - If–else statement
Start
Evaluate condition
Yes No
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 <stdio.h> int main() { int x = 10; if (x > 5) { printf("Greater\n"); } else { printf("Smaller or equal\n"); } return 0; }
| Step | Condition (x > 5) | Result | Branch Taken | Output |
|---|---|---|---|---|
| 1 | 10 > 5 | True | if-block | "Greater\n" printed |
| 2 | End of if-else | - | - | Program ends |
| Variable | Start | After Condition Check | Final |
|---|---|---|---|
| x | 10 | 10 | 10 |
if (condition) {
// code runs if condition true
} else {
// code runs if condition false
}
Checks condition once, runs one branch only.