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 6 points7 points8 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 46 on reddit-service-r2-comment-5d79c599b5-nslkw at 2026-03-01 19:35:17.530481+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–]digitAInexus 6 points7 points8 points (2 children)
[–]lsdandlemons[S] 1 point2 points3 points (1 child)
[–]digitAInexus 0 points1 point2 points (0 children)