# Control Flow in Python(Week 9).
It has been an amazing time at Blockfuse labs. I have learned much ina what I will say is a short while. Last week saw me reach nine weeks here and I couldn’t be more proud because I have not given up after all the tussle. By the way, I am not giving up on this journey.
Now let me walk you through my summary about my week nine… Control flow statements!
Control flow in Python programming language refer to the order in which individual statements, instructions, or function calls are executed or evaluated. By default, Python executes code from top to bottom, that is, if you write a code, python starts with the first line, moves to the second line till it gets to the last line. However, control flow statements allow you to change this sequence, enabling decision-making, repetition, and branching in programs. These statements help a program react differently depending on conditions, repeat tasks, or skip certain steps.
The main types of control flow statements in Python are:
Conditional Statements (if, elif, else) – Used to execute code only if a condition is true.Looping Statements (for, while) – Used to repeat a block of code multiple times.Control Transfer Statements (break, continue, pass) – Used to alter the flow within loops.Control flow is essential for creating dynamic, interactive, and intelligent programs rather than static scripts.
### Below are two examples of flow control statements:
Example 1 – Conditional Statement:
```python
age = 18
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")
```
Here, Python checks the condition age >= 18.
• If it’s True, the program executes the first block and prints "You are eligible to vote.".
• If it’s False, it skips the first block and executes the else block, printing "You are not eligible to vote.".
In our case, age is exactly 18, so the condition is true and the first message is printed.
Example 2 – Loop with Control Statement:
```python
for i in range(5):
if i == 3:
break
print(i)
```
This loop starts with i = 0 and increases by 1 each iteration until it reaches 4 (because range(5) generates 0 to 4).
• The if i == 3: checks if i is equal to 3.
• If true, the break statement stops the loop immediately, so numbers after 2 are not printed.
I hope you understood the little points I made, if you did not, feel free to reach out to me or make corrections in the comments. I wish you a great week ahead. See you!