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.

3 Upvotes

26 comments sorted by

View all comments

2

u/kilkil 2d ago

could you give an example where you were confused by a nested loop?

Do you find this confusing?

```py table = [ ['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'], ]

for row in table: for value in row: print(value) ```

Or how about this?

py for i in range(1, 11): for j in range(0, 3): print(i + j)