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.
int x = 10; if (x > 5) { System.out.println("x is greater than 5"); } System.out.println("Done");
| Step | Condition (x > 5) | Result | Branch Taken | Output |
|---|---|---|---|---|
| 1 | 10 > 5 | true | Execute if block | x is greater than 5 |
| 2 | N/A | N/A | Continue after if | Done |
| 3 | N/A | N/A | Program ends | No more output |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| x | 10 | 10 | 10 | 10 |
If statement syntax:
if (condition) {
// code runs if condition is true
}
Checks condition once.
Runs block only if true.
Skips block if false.