<ContentPage eyebrow="Tutorial" title="Display several tasks" description="Use a list and a loop to number your tasks.">

<TutorialNavigation slug="tutorial-task-list" />

Start with chapter 1's `tasks.tea`. We're going to replace the single title with a list and give each task a number.

## Put the titles in a list

Replace the `title` binding with:

```tea
const tasks = ["Learn Tea", "Build a CLI", "Take a break"]
```

Square brackets create a list. Since each element is a string, Tea infers `List[String]`. A list keeps its elements in order; the first item has index `0` when you access it directly.

## Print each title

Replace the old output statement with:

```tea
var number = 1

for title in tasks
  @println(`${number}. ${title}`)
  number = number + 1
end
```

`for title in tasks` binds each element to `title` in turn. The block closes with `end`. Indent the body by two spaces for readability; it is the `end` keyword that marks the block's boundary.

We use `var` for `number` because it changes on each iteration. Its initial value is an `Int`. The counter starts at `1` because these numbers are for the person using the tool, even though list indexes start at `0`.

Interpolation accepts numbers as well as strings, so there's no need to convert `number` before printing it.

## Run the program

```bash
tea tasks.tea
```

```text
1. Learn Tea
2. Build a CLI
3. Take a break
```

## Complete checkpoint

**`tasks.tea`**

```tea checkpoint="examples/tutorial/tasks/02-task-list/tasks.tea"
const tasks = ["Learn Tea", "Build a CLI", "Take a break"]
var number = 1

for title in tasks
  @println(`${number}. ${title}`)
  number = number + 1
end
```

## Try it yourself

Add a fourth task and print the total number of tasks after the loop.

<details>
<summary>Hint</summary>

Add another string inside the list's square brackets. After `end`, use `@len(tasks)` to get the list length:

```tea
@println(`${@len(tasks)} tasks`)
```

</details>

You now have a collection and a loop. Next, each task will carry its own completion status.

Read more: [lists and inferred types](/docs/types), [length and other built-ins](/reference/builtins).

<TutorialNavigation slug="tutorial-task-list" position="bottom" />

</ContentPage>
