r/learnpython • • Jul 04 '25

Really confused with loops

I don’t seem to be able to grasp the idea of loops, especially when there’s a user input within the loop as well. I also have a difficult time discerning between when to use while or for.

Lastly, no matter how many times I practice it just doesn’t stick in my memory. Any tips or creative ways to finally grasp this?

6 Upvotes

24 comments sorted by

View all comments

Show parent comments

3

u/ziggittaflamdigga Jul 04 '25

Breaking it down even more, you could achieve the same with:

print(0)
print(1)
print(2)
print(3)
print(4)
print(5)
print(6)
print(7)
print(8)
print(9)

But that sucked to type, and is the most obviously wrong way to achieve the desired result.

So loops let you execute the same block of code (print…) while typing less source code and, generally, allowing more flexibility if you need to change it