aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-07-16 13:14:11 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-07-16 13:14:11 -0400
commit158e2312ea5f680b7c8598ef578aefb6cbdd3372 (patch)
treec5ab42fd98dff7c2bf9be090a61b1e0dd639bbc8 /doc
parent15ed47921f1d4305d29db222f501eba899453beb (diff)
parent23dd7f452771b5f6af9d34ad2fb29a82d66b18f3 (diff)
downloadzig-158e2312ea5f680b7c8598ef578aefb6cbdd3372.tar.gz
zig-158e2312ea5f680b7c8598ef578aefb6cbdd3372.zip
Merge branch 'JohnathanFL-master'
closes #2900 closes #2894
Diffstat (limited to 'doc')
-rw-r--r--doc/langref.html.in30
1 files changed, 30 insertions, 0 deletions
diff --git a/doc/langref.html.in b/doc/langref.html.in
index bb54a91c80..b5fe464c35 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -1733,6 +1733,36 @@ test "array initialization with function calls" {
}
{#code_end#}
{#see_also|for|Slices#}
+
+ {#header_open|Multidimensional Arrays#}
+ <p>
+ Mutlidimensional arrays can be created by nesting arrays:
+ </p>
+ {#code_begin|test|multidimensional#}
+const std = @import("std");
+const assert = std.debug.assert;
+
+const 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" {
+ // Access the 2D array by indexing the outer array, and then the inner array.
+ assert(mat4x4[1][1] == 1.0);
+
+ // Here we iterate with for loops.
+ for (mat4x4) |row, row_index| {
+ for (row) |cell, column_index| {
+ if (row_index == column_index) {
+ assert(cell == 1.0);
+ }
+ }
+ }
+}
+ {#code_end#}
+ {#header_close#}
{#header_close#}
{#header_open|Vectors#}