Python Control Flow Basics: Conditional Statements and Loops

✅ *Python Basics: Part-3* *Control Flow in Python* 🔁🧠 🎯 *What is Control Flow?* Control flow allows your code to make decisions and repeat actions using conditions and loops. 🔹 *1. Conditional Statements (if, elif, else)* Used to execute code based on conditions: ```python age = 18 if age >= 18: print("You are an adult") elif age > 13: print("You are a teenager") else: print("You are a child") ``` 🔹 *2. Loops* ● *For Loop* – Used to iterate over a sequence (list, string, etc.) ```python fruits = ["apple", "banana", "cherry"] for fruit in fruits: print(fruit) ``` ● *While Loop* – Repeats as long as a condition is true ```python count = 0 while count < 5: print(count) count += 1 ``` 🔹 *3. Loop Control Statements* - `break`: Exit the loop - `continue`: Skip current iteration - `pass`: Placeholder that does nothing ```python for i in range(5): if i == 3: break print(i) ``` 💬 *Double Tap ❤️ for Part-4!*

To view or add a comment, sign in

Explore content categories