Iterating over matrix elements
Each element of the matrix has two indices, so you need to use a nested loop to iterate over all the elements.
Usually a matrix is iterated row by row: the outer loop iterates over the row indices, while the inner loop iterates over the column indices.
But if necessary, you can iterate over the matrix and the columns, then the cycles are reversed.