Add multidimensional array example

master
JohnathanFL 2019-07-15 17:20:56 -05:00 committed by Andrew Kelley
parent 15ed47921f
commit 475a181028
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
1 changed files with 21 additions and 0 deletions

View File

@ -1731,6 +1731,27 @@ test "array initialization with function calls" {
assert(more_points[4].y == 6);
assert(more_points.len == 10);
}
// Multidimensional arrays are declared by simply adding another array before the existing array
var 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" {
// Multidimensional arrays can be accessed as expected from other languages...
assert(mat4x4[1][1] == 1.0);
// or iterated over like any other array
for (mat4x4) |row, rowNum| {
for (row) |column, colNum| {
if (rowNum == colNum) {
assert(column == 1.0);
}
}
}
}
{#code_end#}
{#see_also|for|Slices#}
{#header_close#}