Concept Flow - If–else execution flow
Start
Evaluate Condition
Execute If
End
The program checks a condition. If true, it runs the 'if' block; if false, it runs the 'else' block, then continues.
Jump into concepts and practice - no test required
x = 10 if x > 5: print("x is greater than 5") else: print("x is 5 or less")
| Step | Condition (x > 5) | Result | Branch Taken | Output |
|---|---|---|---|---|
| 1 | 10 > 5 | True | If block | "x is greater than 5" printed |
| 2 | - | - | End | Execution stops after if block |
| Variable | Start | After Step 1 | Final |
|---|---|---|---|
| x | undefined | 10 | 10 |
if condition:
# run this if True
else:
# run this if False
The program checks the condition once.
Runs only one block based on True/False.
Then continues after the if-else.if-else statement do in Python?age = 18
if age >= 18:
print('Adult')
else:
print('Minor')num = 5
if num > 0
print('Positive')
else:
print('Non-positive')