Hi connections!
Today at Payilagam Institute, I explored an important programming concept in Python — Flow Control Statements. These help control the direction and logic of a program.
What I Learned: Flow Control Types in Python
- Conditional Statements
Used to make decisions based on conditions.
Example: if, elif, elseLooping Statements
Used to repeat a block of code multiple times.
Example: for, whileControl Statements
Modify the flow of loops.
Example: break, continue, passException Handling
Used to handle errors without crashing the program.
Example: try, except, finallyPass Statement
Acts as a placeholder when no action is required.
Example: pass
Example Program (All in One):
x = 10
1. Conditional Statement
if x > 5:
print("x is greater than 5")
2. Looping Statement
for i in range(4):
if i == 2:
continue # 3. Control Statement (continue)
print("Loop value:", i)
4. Exception Handling
try:
result = x / 0
except ZeroDivisionError:
print("Cannot divide by zero")
finally:
print("This always runs")
5. Pass Statement
def future_feature():
pass
print("Program executed successfully!")
Top comments (0)