about summary refs log tree commit diff
path: root/lang/zig/multidim.zig
blob: bf30c806d0bd25484105e370b56e419a77baaf7c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const expect = @import("std").testing.expect;

const mat4x4 = [4][4]f32{
    [_]f32{ 1.0, 0.0, 0.0, 0.0 },
    [_]f32{ 0.0, 1.0, 0.0, 1.0 },
    [_]f32{ 0.0, 0.0, 1.0, 0.0 },
    [_]f32{ 0.0, 0.0, 0.0, 1.0 },
};

test "multidimensional arrays" {
    // Access the 2D array by indexing the outer array,
    // and then the inner array.
    expect(mat4x4[1][1] == 1.0);

    // Here we iterate with for loops.
    for (mat4x4) |row, row_index|
        for (row) |cell, column_index|
            if (row_index == column_index)
                expect(cell == 1.0);
}