Loops in Python
📘 Python
👁 62 views
📅 Nov 05, 2025
⏱ Estimated reading time: 1 min
Loops in Python
Loops are used to execute a block of code repeatedly based on a condition.
1. for Loop
-
Iterates over a sequence (list, tuple, string, or range).
2. while Loop
-
Repeats as long as the condition is True.
3. Nested Loops
-
Place one loop inside another for complex iterations.
4. Loop Control Statements
| Statement | Description | Example |
|---|---|---|
break | Exit the loop immediately | if i == 3: break |
continue | Skip the current iteration | if i % 2 == 0: continue |
pass | Do nothing, acts as a placeholder | pass |
Example:
5. else with Loops
-
Executed when the loop completes normally (no
break).
6. Key Points
-
forloops are sequence-based,whileloops are condition-based. -
Use nested loops for multi-dimensional data.
-
breakstops the loop,continueskips an iteration,passis a placeholder. -
elsewith loops runs only if the loop ends naturally.
🔒 Some advanced sections are available for Registered Members
Register Now
Register Now
Share this Post
← Back to Tutorials