authorgravatar for jfl747076@gmail.comJohnathanFL <jfl747076@gmail.com> 2019-07-15 17:20:56-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-16 13:02:30-04:00
log475a1810282f338f2808fb1fdc66b4b5273aabb4
treef8d6dd8efcf748bd64a66ab8e0f8c1b4e0de673c
parent15ed47921f1d4305d29db222f501eba899453beb
signature Commit is signed but in an unrecognized format.

Add multidimensional array example


1 files changed, 21 insertions(+), 0 deletions(-)

doc/langref.html.in+21
......@@ -1731,6 +1731,27 @@ test "array initialization with function calls" {
17311731 assert(more_points[4].y == 6);
17321732 assert(more_points.len == 10);
17331733}
1734
1735// Multidimensional arrays are declared by simply adding another array before the existing array
1736var mat4x4 = [4][4]f32{
1737 [_]f32{1.0, 0.0, 0.0, 0.0},
1738 [_]f32{0.0, 1.0, 0.0, 1.0},
1739 [_]f32{0.0, 0.0, 1.0, 0.0},
1740 [_]f32{0.0, 0.0, 0.0, 1.0}
1741};
1742test "multidimensional arrays" {
1743 // Multidimensional arrays can be accessed as expected from other languages...
1744 assert(mat4x4[1][1] == 1.0);
1745
1746 // or iterated over like any other array
1747 for (mat4x4) |row, rowNum| {
1748 for (row) |column, colNum| {
1749 if (rowNum == colNum) {
1750 assert(column == 1.0);
1751 }
1752 }
1753 }
1754}
17341755 {#code_end#}
17351756 {#see_also|for|Slices#}
17361757 {#header_close#}