Concept Flow - If statement execution flow
Start
Evaluate condition
Execute if-block
End if-block
No
Skip if-block
End
The program checks the condition. If true, it runs the if-block. If false, it skips it and continues.
x = 10 if x > 5: print("x is greater than 5") print("Done")
| Step | Action | Condition (x > 5) | Branch Taken | Output |
|---|---|---|---|---|
| 1 | Evaluate condition | 10 > 5 | Yes | |
| 2 | Execute if-block | x is greater than 5 | ||
| 3 | Execute next statement | Done | ||
| 4 | End | Program ends |
| 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
Behavior:
- Condition checked first
- If true, run code inside if-block
- If false, skip if-block
Key rule: Only runs if condition is true.