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 strings

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 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 how a sprite would "say" the items in the list using the variable "value" in the say command. In this example, the default list of stings has been modified. It is a list of comments about animals. The result will be the sprite "saying" each of the items in the list.
Note: Without the stage.wait() the words would go by so fast that you may not see them!

Lists List of Strings
Loops Loop through List
my_list = ["Cats are Cool", "I Like Dogs", "Birds Sing"]
sprite = codesters.Sprite("person1")

for value in my_list:
    sprite.say(value)
    stage.wait(1)