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" {...@@ -1731,29 +1731,38 @@ test "array initialization with function calls" {
1731 assert(more_points[4].y == 6);1731 assert(more_points[4].y == 6);
1732 assert(more_points.len == 10);1732 assert(more_points.len == 10);
1733}1733}
1734 {#code_end#}
1735 {#see_also|for|Slices#}
17341736
1735// Multidimensional arrays are declared by simply adding another array before the existing array1737 {#header_open|Multidimensional Arrays#}
1736var mat4x4 = [4][4]f32{1738 <p>
1737 [_]f32{1.0, 0.0, 0.0, 0.0},1739 Mutlidimensional arrays can be created by nesting arrays:
1738 [_]f32{0.0, 1.0, 0.0, 1.0},1740 </p>
1739 [_]f32{0.0, 0.0, 1.0, 0.0},1741 {#code_begin|test|multidimensional#}
1740 [_]f32{0.0, 0.0, 0.0, 1.0}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 },
1741};1750};
1742test "multidimensional arrays" {1751test "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.
1744 assert(mat4x4[1][1] == 1.0);1753 assert(mat4x4[1][1] == 1.0);
17451754
1746 // or iterated over like any other array1755 // Here we iterate with for loops.
1747 for (mat4x4) |row, rowNum| {1756 for (mat4x4) |row, row_index| {
1748 for (row) |column, colNum| {1757 for (row) |cell, column_index| {
1749 if (rowNum == colNum) {1758 if (row_index == column_index) {
1750 assert(column == 1.0);1759 assert(cell == 1.0);
1751 }1760 }
1752 }1761 }
1753 }1762 }
1754}1763}
1755 {#code_end#}1764 {#code_end#}
1756 {#see_also|for|Slices#}1765 {#header_close#}
1757 {#header_close#}1766 {#header_close#}
17581767
1759 {#header_open|Vectors#}1768 {#header_open|Vectors#}