BlocosIA Wiki Editor

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.

  1. In Variables, click "Make a variable" and create the variable "fruits".
  2. Choose a sprite and drag "when green flag clicked" with "set fruits to" below it.
  3. In the Arrays category, take "list with apple, banana, grape" and snap it into "set fruits to".
  4. Click the + of the "list with" block and type one more fruit.
  5. In Control, snap "for each item in list" below and put the "fruits" variable in the list slot.
  6. Inside "for each", put "say … for 1 seconds" with the "item" variable inside.
  7. Click the flag: the sprite says each fruit and the list box shows on the stage.
  8. Challenge: use "add … to the end of list fruits" when space is pressed. (challenge)

Open in the editor