Local names: let and var
You will learn
When to use let and when var, and how a var is updated.
let a = w * h; gives a name to a value inside a function body. var i : u8 = 0; declares a name that may change, and i = i + 1; changes it. Use let when the value is computed once, var when a loop updates it. These names live only inside the function; the module level uses const.
Try it
Change let to var in area and check the verdict; then explain why let reads better there.

Where let, var and const live in a t27 spec and whether the name may change. Lesson 13 of the t27 basics course.
specs/basics/13_local_names.t27
// SPDX-License-Identifier: Apache-2.0
; t27 basics, lesson 13: Local names: let and var.
; Inside a function, let names a value once and var names one that changes.
module basics_13_local_names;
pub fn area(w: u16, h: u16) -> u16 {
let a = w * h;
return a;
}
pub fn count_up(n: u8) -> u8 {
var i : u8 = 0;
while (i < n) {
i = i + 1;
}
return i;
}
pub const SIDE : u16 = 12;
test a_square_of_side_12 {
assert SIDE * SIDE == 144;
}
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.