Tea — a strongly typed scripting language
Tea
DocsPlaygroundExamplesReferenceCommunity
GitHub

Tea Language

A strongly typed scripting language for native tools.

© 2026 Tea Language.

Agent documentationContributingCommunityRepository

Get Started

InstallationGetting StartedCLI

Tutorial

Build a CLI with Tea1. Display your first task2. Display several tasks3. Track task status4. Accept commands5. Read saved tasks6. Add tasks7. Complete tasks8. Organize and test9. Build your executable

Language

SyntaxTypesFunctionsStructsGenericsPattern MatchingError HandlingModulesTesting

Project

Code StyleContributing

Read as Markdown

Tutorial

Display several tasks

Use a list and a loop to number your tasks.

Chapter 2 of 9 · Build a CLI with Tea

Choose a chapter
  1. Build a CLI with Tea
  2. 1. Display your first task
  3. 2. Display several tasks
  4. 3. Track task status
  5. 4. Accept commands
  6. 5. Read saved tasks
  7. 6. Add tasks
  8. 7. Complete tasks
  9. 8. Organize and test
  10. 9. Build your executable

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:

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:

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

tea tasks.tea
1. Learn Tea
2. Build a CLI
3. Take a break

Complete checkpoint

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.

Hint

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

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

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

Read more: lists and inferred types, length and other built-ins.

Previous1. Display your first taskNext3. Track task status