Loops
Use the for
loop to iterate over a data structure.
colors = ["red", "blue", "green", "pink"]
for color in colors:
# This will print the color name uppercased, e.g. 'RED'
print(color.upper())
The while
loop is used to do an action indefinitely.
color = None
# Ask about a color until "red" is provided
while color != "red":
color = input("What's the right color? ")