Lesson contents

Fixed values

Give a fixed value a name and reuse it wherever the same amount is needed.

Simple example

Use the same factor twice.

Start3 × 2
Result6
lesson.zig
const std = @import("std");

pub fn main() !void {
    const factor = 3;
    std.debug.print("{any}\n", .{factor * 2});
}
Output
6
Advertisements

Everyday examples

Each bus ticket costs 4 coins. What do three tickets cost?

Start4 × 3
Result12
lesson.zig
const std = @import("std");

pub fn main() !void {
    const fare = 4;
    std.debug.print("{any}\n", .{fare * 3});
}
Output
12
Run the example
Terminal
zig run lesson.zig
Official documentation