Lists: one variable with many values
Medium · Store fruits in a list and use "for each" to say them one by one.
Interactive tutorial: the editor checks each step by itself.
- In Variables, click "Make a variable" and create the variable "fruits".
- Choose a sprite and drag "when green flag clicked" with "set fruits to" below it.
- In the Arrays category, take "list with apple, banana, grape" and snap it into "set fruits to".
- Click the + of the "list with" block and type one more fruit.
- In Control, snap "for each item in list" below and put the "fruits" variable in the list slot.
- Inside "for each", put "say … for 1 seconds" with the "item" variable inside.
- Click the flag: the sprite says each fruit and the list box shows on the stage.
- Challenge: use "add … to the end of list fruits" when space is pressed. (challenge)