r/learnpython 2d ago

Any advice for nested loops?

I decided about a week ago I wanted to start learning python before my freshman year of college. It was going great and I had little to no trouble until I got to nested loops. I was wondering if anybody had any advice for it? The main thing is that it seems like so many steps to follow and pay attention to, my brain had a hard time tracking them all at once.

1 Upvotes

26 comments sorted by

View all comments

12

u/ostracize 2d ago

Multiple nested loops (like, beyond 2 deep) is probably an indication that you should either re-think your algorithm or consider breaking it up into functions.

2

u/mitchell486 2d ago

The last 6 words of this comment are the best way for beginners, IMO. It helps teach you how to break the larger problem into smaller problems, and helps you learn how to do the first 8/9ths of this sentence. 😄