Lesson 2.2: Control Structures – if-else, loops
Control structures in Python allow you to control the flow of execution in your program. They help in making decisions and repeating tasks.
1. Conditional Statements (if, elif, else)
Used when you want your code to make decisions based on conditions.
Syntax:
Example:
2. Looping Statements
Loops are used to execute a block of code multiple times.
(a) for loop – Iterates over a sequence (like list, tuple, string, range).
(b) while loop – Runs until the condition becomes False.
3. Loop Control Statements
-
break → exits the loop immediately.
-
continue → skips current iteration, goes to next.
-
pass → does nothing (used as placeholder).
Example:
✅ In Summary:
-
Use if-elif-else for decision-making.
-
Use for loop for known iterations, while loop for unknown.
-
Use break, continue, pass to control loop flow.
