authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-16 13:13:21-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-16 13:13:21-04:00
log23dd7f452771b5f6af9d34ad2fb29a82d66b18f3
treec5ab42fd98dff7c2bf9be090a61b1e0dd639bbc8
parent475a1810282f338f2808fb1fdc66b4b5273aabb4
signaturelock-open Commit is signed but in an unrecognized format.

organize the docs and some rewording


1 files changed, 22 insertions(+), 13 deletions(-)

doc/langref.html.in+22-13
......@@ -1731,29 +1731,38 @@ test "array initialization with function calls" {
17311731 assert(more_points[4].y == 6);
17321732 assert(more_points.len == 10);
17331733}
1734 {#code_end#}
1735 {#see_also|for|Slices#}
17341736
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}
1737 {#header_open|Multidimensional Arrays#}
1738 <p>
1739 Mutlidimensional arrays can be created by nesting arrays:
1740 </p>
1741 {#code_begin|test|multidimensional#}
1742const std = @import("std");
1743const assert = std.debug.assert;
1744
1745const mat4x4 = [4][4]f32{
1746 [_]f32{ 1.0, 0.0, 0.0, 0.0 },
1747 [_]f32{ 0.0, 1.0, 0.0, 1.0 },
1748 [_]f32{ 0.0, 0.0, 1.0, 0.0 },
1749 [_]f32{ 0.0, 0.0, 0.0, 1.0 },
17411750};
17421751test "multidimensional arrays" {
1743 // Multidimensional arrays can be accessed as expected from other languages...
1752 // Access the 2D array by indexing the outer array, and then the inner array.
17441753 assert(mat4x4[1][1] == 1.0);
17451754
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);
1755 // Here we iterate with for loops.
1756 for (mat4x4) |row, row_index| {
1757 for (row) |cell, column_index| {
1758 if (row_index == column_index) {
1759 assert(cell == 1.0);
17511760 }
17521761 }
17531762 }
17541763}
17551764 {#code_end#}
1756 {#see_also|for|Slices#}
1765 {#header_close#}
17571766 {#header_close#}
17581767
17591768 {#header_open|Vectors#}