Need Help Understanding Loops in Python #187171
-
|
Hey everyone, I'm trying to figure how loops work as I'm new to python. I get the basics idea of for and while loops however I get confused when to use them. For example, when would you use a for loop instead of a while loop? Any simple explanations or examples would be very helpful |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
For example: for i in range(5): |
Beta Was this translation helpful? Give feedback.
-
🐍 Python Basics Practice Repo👋 Hi everyone! 🎯 The goal is to help learners (like me!) practice, understand, and build confidence step by step. 📂 Check it out here: For Loop 💡 Inside you’ll find:
Let’s learn, share, and grow together 🚀 |
Beta Was this translation helpful? Give feedback.
-
|
Loops in Python are used to repeat actions multiple times. There are two main types:
for i in range(5): This prints numbers from 0 to 4.
x = 0 This runs until the condition becomes false. Key idea:
Try writing small examples yourself — that’s the best way to learn. Hope this helps! Let me know if you'd like more examples. |
Beta Was this translation helpful? Give feedback.
For example:
for i in range(5):
if i == 3:
break
print(i)
This prints 0, 1, 2 and then stops.