commit 475a1810282f338f2808fb1fdc66b4b5273aabb4 (tree)
parent 15ed47921f1d4305d29db222f501eba899453beb
Author: JohnathanFL <jfl747076@gmail.com>
Date: Mon, 15 Jul 2019 17:20:56 -0500
Add multidimensional array example
Diffstat:
1 file changed, 21 insertions(+), 0 deletions(-)
diff --git 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#}