# Repeating things

`repeat:` makes copies of a container.

- `repeat: task in tasks` makes one copy per item. `task` is that copy's item, and the copies
  follow the list: add an item and a copy appears.
- `repeat: 5` makes five copies; `repeat: 3, 3` makes a grid of 3 columns and 3 rows.
- In a copy, `index` is its place (from 0). In a grid, `x` and `y` are its column and row.
- Containers written inside a copy see that copy's item, `index`, `x` and `y` too.
- The copies belong to the parent, like children written out one by one. `repeat: 3` is the same
  as listing the container three times: the parent's `arrange` lines them up and its
  `space_between` is the gap. A grid is one block in the parent; the parent's `space_between` is
  the gap between its cells, and with `spread` or `even` the grid fills the parent and spreads them.

```vi
main home:
  children:
    tiles

tiles:
  size: max, 30
  arrange: row, spread
  space_inside: 10
  children:
    tile

tile:
  repeat: 3
  size: 20
  color: yellow
  shape: rounded
```

```vi
tasks = ["Buy milk", "Call Sam", "Water the plants"]

main home:
  space_inside: 20
  space_between: 8
  children:
    task_row
    add:
      button: "Add a task"
      on_tap: tasks.add("Task {tasks.count + 1}")

task_row:
  repeat: task in tasks
  size: max, auto
  space_inside: 12
  color: gray[100]
  shape: rounded
  text: "{index + 1}. {task}"
  on_hold: tasks.remove(task)
```

```vi
main board:
  arrange: center
  children:
    grid:
      size: max, auto
      arrange: row, center
      children:
        cell

cell:
  repeat: 3, 3
  size: 30
  space_around: 2
  shape: rounded
  color: blue[200] if (x == y) else blue[400]
  arrange: center
  text: "{x}, {y}"
  on_tap: cell.at(x, y).color = orange[400]
```

Reach one copy with `.at()`: `cell.at(1, 1)` in a grid, `task_row.at(4)` in a list.
