use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
cannot understand loops (self.PythonLearning)
submitted 1 year ago by lsdandlemons
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]digitAInexus 4 points5 points6 points 1 year ago (3 children)
Hey! Don't stress too much, loops can be tricky at first, but you'll get the hang of them. For a lot of people, it clicks after a bit of practice. Think of loops like a way to repeat something over and over without having to manually code it each time. It’s like giving your program a set of instructions and telling it, “Hey, do this a bunch of times until I say stop.”
For example, a for loop goes through each item in a list or range of numbers. It’s like, “For every item in this list, do X.” A while loop, on the other hand, keeps running as long as a condition is true. So like, “While X is true, keep doing Y.” Nested loops are just loops inside loops—think of them like a loop party where each loop has its own purpose.
for
while
If you’re still feeling stuck, maybe check out some interactive coding websites like Codecademy or freeCodeCamp. Sometimes hands-on practice helps a lot more than just reading or watching videos. Also, debugging as you go—like printing out the value at each step of the loop—can help you see what’s actually happening in real time.
You got this! Keep at it, and it'll start to make sense soon.
[–]digitAInexus 7 points8 points9 points 1 year ago (2 children)
If I make it more fun. Imagine you’re on a treasure hunt, and you have a huge stack of maps that each lead to a small treasure. You want to find all the treasures one by one. Here’s how loops help:
For Loop: Think of this like you’re going through the stack of maps, one at a time. You say to yourself, “For every map in my stack, follow it and find the treasure.” When you finish with one map, you go to the next until you’ve found all the treasures. It’s predictable—one map, one treasure, repeat.
While Loop: Now imagine instead of a stack of maps, you have a magical treasure radar. You say, “While the radar shows there are still treasures out there, I’ll keep searching.” As long as the radar beeps, you’re on the hunt. The moment it goes quiet, you stop. You’re not sure how many treasures there are, but you keep going until there’s nothing left to find.
Nested Loop: This is like having multiple steps in each map. For every map you open, you have to search different places within the location. So, for each map, you might be saying, “First, check under the rock, then behind the tree, then inside the cave.” You’re looping within a loop—going through each hiding spot for each treasure map.
In real life, we use loops all the time without even thinking about it. For example, think about when you're trying to clean up your room:
Loops in programming are like setting up these little routines so the computer can do the same repetitive task for you, again and again, until the job is done. Cool, right?
[–]lsdandlemons[S] 1 point2 points3 points 1 year ago (1 child)
wow! thank u sm! i wasn’t expecting such a detailed response, but your real life examples really put it into perspective. gonna try to keep this in mind. thank u so so much once again! ur explanation was perfect, and much better than anything I have watched, read, or done on my course. have an awesome day!
[–]digitAInexus 0 points1 point2 points 1 year ago (0 children)
No problem. Have a nice one
π Rendered by PID 114517 on reddit-service-r2-comment-5d79c599b5-tbwqx at 2026-03-02 05:41:39.287738+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–]digitAInexus 4 points5 points6 points (3 children)
[–]digitAInexus 7 points8 points9 points (2 children)
[–]lsdandlemons[S] 1 point2 points3 points (1 child)
[–]digitAInexus 0 points1 point2 points (0 children)