I worked on for loops nested today. It seems as though this type of for loops are convenient for going through long lists of elements.
In the book they used the example of figuring out how many combinations can be created with two different lists. A first name and last name thing.
Coding to cycle through each list is much faster than manual labor lol.
I’ll try one with yall.
I created three lists above – cities, states, and combos. Combos is to place the results.
The outer loop assigns each element from cities to each_city variable.
The inner loop assigns each element from states to a_state variable.
The elements from the first two lists are stored in combos. Each elements is added to the end of the list. It’ll be like mixing up the cities and states. Fun, right?
Can you guess how many combinations there are?
Ok, that’s it for tonight. See you tomorrow!