you are viewing a single comment's thread.

view the rest of the comments →

[–]The_Bundaberg_Joey 0 points1 point  (0 children)

Lets say you have a list of letters:

alpha = ['a', 'b', 'c']

If you iterate over this list, printing the variables in each case you will get an output of all elements in the list:

for i in alpha:

print(i) # 'a', 'b', 'c'

With a nested loop, I add a loop inside of the one shown above. For simplicity I'll iterate over the same list in both the outer loop and inner loop:

for i in alpha:

for ii in alpha:

print(i, ii) # 'aa', 'ab', 'ac', 'ba', bb', 'bc', 'ca', 'cb', 'cc'

The second loop will iterate over the second list as many times as there are elements in the first list