🔀 Control Flow Statements
Last Updated: 13th August 2025
Definition:
Control Flow Statements decide which part of your program will run, when, and how many times. They give your program the power to make decisions and repeat tasks.
Hinglish Tip 🗣: Control Flow ka kaam hai decide karna ki program kaunsa step pehle karega, kaunsa baad me,kishko repeat karenga aur kaunsa skip karega.
Control Flow is Important ?
Without control flow, Python would just run your code line-by-line from top to bottom without any decision-making. Control flow lets you:
- Run different code based on condition.
- Repeat code multiple times.
- Skip or stop parts of loop.
Example:
Imagine you are travelling:
- Conditional: If it’s raining, take an umbrella.
- Loop: Walk until you reach your destination.
- Jump: If you see danger, stop immediately.
Main Categories
- Conditional Statements — Decision making.
- Looping Statements — Repeat a block of code.
- Transfer/Jump Statements — Change the normal sequence of execution.
| Category | Keywords | Purpose |
|---|---|---|
| Conditional | if, elif, else, match | Run different code based on condition |
| Looping | for, while | Repeat code multiple times |
| Jump | break, continue, pass | Skip or stop parts of loop |
Code Previews:
x = 10
if x > 0: # Conditional
print("Positive number")
for i in range(3): # Loop
print(i)
for i in range(5): # Jump example
if i == 3:
break
print(i)
💡 Don’t worry! We’ll explore each of these in full detail in the next sections.