Arrays
You will learn
How to declare an array, read an item, and which index is the last one.
An array type is the length in square brackets followed by the item type: [5]u8 is five unsigned bytes. The value lists the items in square brackets. Index 0 holds the item at the start, so in an array of 5 the last index is 4. A test reads an item with PRIMES[4]. Keep the declared length and the list in step: the checker in this browser does not catch a length that disagrees with the list.
Try it
Add a sixth prime to PRIMES, fix the length, and write an assert for index 5.

A t27 array drawn as a row of cells with their indexes, from the lesson spec. Lesson 7 of the t27 basics course.
specs/basics/07_arrays.t27
// SPDX-License-Identifier: Apache-2.0
; t27 basics, lesson 7: Arrays.
; An array has a length and a type, [5]u8, and its items are read by index from 0.
module basics_07_arrays;
pub const PRIMES : [5]u8 = [2, 3, 5, 7, 11];
pub const DIGITS : [3]str = ["zero", "one", "two"];
test indexes_start_at_zero {
assert PRIMES[0] == 2;
assert PRIMES[4] == 11;
assert DIGITS[2] == "two";
}
All lessons
Module 1 · A spec file
What a .t27 file holds: a module line, prose lines and comments.
Module 2 · Values and types
Constants, the width of a whole number, and true, false and text.
Module 3 · Arrays, trits and expressions
Lists of values, the three values of a trit, and what operators compute.
Module 4 · Tests and functions
A test block, several small tests in one spec, and a function with typed inputs.
Module 5 · Inside a function
Names with let and var, choices with if and switch, and loops.
Module 6 · Visibility and your own types
What pub shares with other modules, and the structs and enums you declare.
Module 7 · Modules, rules and gen-ts
Reading another module, stating a rule that always holds, and a spec turned into TypeScript.
Module 8 · The compiler and tri
The backends t27c writes, the stages it reads a spec in, and the tri command.
Module 9 · Errors, a program, what next
Reading a compiler error, one small complete program, and the course to take next.