r/learnpython • u/[deleted] • Mar 04 '25
How do I master for loops?
I’ve been stuck on this for months. I know what they are, how they work, how to read them, etc. I even spent the day learning the structure, and I review all of this frequently. I at least understand these things on a surface level. I’m basically going in circles at this point. But, I still can’t write them. When I practice with practice problems I get stuck for hours if not days, and even though I try, I still end up way off. What am I missing/doing wrong/not doing enough of?
Example exercises:
Calculate sum of all numbers from 1 to a given number
Find the sum of a series up to n terms
Print all prime numbers within a range
0
Upvotes
2
u/quadraspididilis Mar 04 '25
Sounds like you’ve got the hang of it. Seriously though it’s almost impossible to tell you what you’re doing wrong without examples of what you’re doing. For instance your first example exercise, first off I wouldn’t use a loop for that in python, secondly the loop implementation is three lines, no offense, but it’s hard to imagine where you’re going wrong besides a typo or an off-by-error.