Codesters FAQ is the official FAQ site for codesters.com. We will continue to update this blog with the most common questions we receive form teachers using Codesters.

Loop through a list of colors

Looping through a list will store an item from the list in a variable. When the loop starts, it will store the first item in the variable. When it loops back through again, it will replace the value of the variable with the second item in the list and so on until all of the items in the list have been used.   The example here shows what the blocks look like when dragged into the code editor.  The variable "value" will hold each item in the list. In this example, the default list called "Rainbow" is used. It is a list of 7 colors. The results will be a square that changes color 7 times. Be creative and add more colors to the list!
Note: Without the stage.wait() the colors would change so fast that you would not see them!

Lists Rainbow
Loops Loop through List
my_list = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"]

for value in my_list:
    sprite = codesters.Square(0, 0, 100, value)
    stage.wait(1)