| ... | ... | @@ -1731,6 +1731,27 @@ test "array initialization with function calls" { |
| 1731 | 1731 | assert(more_points[4].y == 6); |
| 1732 | 1732 | assert(more_points.len == 10); |
| 1733 | 1733 | } |
| 1734 | |
| 1735 | // Multidimensional arrays are declared by simply adding another array before the existing array |
| 1736 | var mat4x4 = [4][4]f32{ |
| 1737 | [_]f32{1.0, 0.0, 0.0, 0.0}, |
| 1738 | [_]f32{0.0, 1.0, 0.0, 1.0}, |
| 1739 | [_]f32{0.0, 0.0, 1.0, 0.0}, |
| 1740 | [_]f32{0.0, 0.0, 0.0, 1.0} |
| 1741 | }; |
| 1742 | test "multidimensional arrays" { |
| 1743 | // Multidimensional arrays can be accessed as expected from other languages... |
| 1744 | assert(mat4x4[1][1] == 1.0); |
| 1745 | |
| 1746 | // or iterated over like any other array |
| 1747 | for (mat4x4) |row, rowNum| { |
| 1748 | for (row) |column, colNum| { |
| 1749 | if (rowNum == colNum) { |
| 1750 | assert(column == 1.0); |
| 1751 | } |
| 1752 | } |
| 1753 | } |
| 1754 | } |
| 1734 | 1755 | {#code_end#} |
| 1735 | 1756 | {#see_also|for|Slices#} |
| 1736 | 1757 | {#header_close#} |