Zig

Print

std.debug.print("Hello, {s}!\n", .{"World"});

Variables

const x: i32 = 4;
var x: u32 = 4;

Data types

// basic types
const x: i32;
const x: i64;
const x: u32;
const x: u64;
const x: f64;
const x: bool;

// array
const my_array = [3]u32{ 1, 2, 3 };

// vector
const x: Vector(3, u32) = .{ 1, 2, 3 };

// enum
const Color = enum { red, green, blue };

// struct
const User = struct {
    username: []const u8,
    email: []const u8,
}

Operators

// Arithmetic operators
% // modulo (remainder)

// Logical operators
== // equal
!= // not equal
&& // AND
|| // OR

// Bitwise operation
& // AND
| // OR
^ // XOR
~ // NOT

Control flow

// if-else
if (a < b) {
    // statement
} else {
    // statement
}

// While loop
while (i < 3) {
    // statement
}

Functions

fn add(x: u32, y: u32) u32 {
    return x + y;
}