aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnathanFL <jfl747076@gmail.com>2019-07-15 17:20:56 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-07-16 13:02:30 -0400
commit475a1810282f338f2808fb1fdc66b4b5273aabb4 (patch)
treef8d6dd8efcf748bd64a66ab8e0f8c1b4e0de673c
parent15ed47921f1d4305d29db222f501eba899453beb (diff)
downloadzig-475a1810282f338f2808fb1fdc66b4b5273aabb4.tar.gz
zig-475a1810282f338f2808fb1fdc66b4b5273aabb4.zip
Add multidimensional array example
-rw-r--r--doc/langref.html.in21
1 files changed, 21 insertions, 0 deletions
diff --git a/doc/langref.html.in b/doc/langref.html.in
index bb54a91c80..ca473cb383 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -1731,6 +1731,27 @@ test "array initialization with function calls" {
assert(more_points[4].y == 6);
assert(more_points.len == 10);
}
+
+// Multidimensional arrays are declared by simply adding another array before the existing array
+var 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" {
+ // Multidimensional arrays can be accessed as expected from other languages...
+ assert(mat4x4[1][1] == 1.0);
+
+ // or iterated over like any other array
+ for (mat4x4) |row, rowNum| {
+ for (row) |column, colNum| {
+ if (rowNum == colNum) {
+ assert(column == 1.0);
+ }
+ }
+ }
+}
{#code_end#}
{#see_also|for|Slices#}
{#header_close#}