authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-16 13:14:11-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-16 13:14:11-04:00
log158e2312ea5f680b7c8598ef578aefb6cbdd3372
treec5ab42fd98dff7c2bf9be090a61b1e0dd639bbc8
parent15ed47921f1d4305d29db222f501eba899453beb
parent23dd7f452771b5f6af9d34ad2fb29a82d66b18f3
signaturelock-open Commit is signed but in an unrecognized format.

Merge branch 'JohnathanFL-master'

closes #2900 closes #2894

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

doc/langref.html.in+30
...@@ -1733,6 +1733,36 @@ test "array initialization with function calls" {...@@ -1733,6 +1733,36 @@ test "array initialization with function calls" {
1733}1733}
1734 {#code_end#}1734 {#code_end#}
1735 {#see_also|for|Slices#}1735 {#see_also|for|Slices#}
1736
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 },
1750};
1751test "multidimensional arrays" {
1752 // Access the 2D array by indexing the outer array, and then the inner array.
1753 assert(mat4x4[1][1] == 1.0);
1754
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);
1760 }
1761 }
1762 }
1763}
1764 {#code_end#}
1765 {#header_close#}
1736 {#header_close#}1766 {#header_close#}
17371767
1738 {#header_open|Vectors#}1768 {#header_open|Vectors#}