To iterate over a Two Dimensional Array in Swift, you can use nested loops.
In this example,
matrix
.let matrix = [[0, 1, 2], [1, 2, 3], [2, 3, 4]]
for row in matrix {
for element in row {
print(element, terminator: " ")
}
print()
}
0 1 2 1 2 3 2 3 4
In this example,
matrix
.let matrix = [["Hello", "World"], ["Swift", "Programming"]]
for row in matrix {
for element in row {
print(element, terminator: " ")
}
print()
}
Hello World Swift Programming
In this tutorial, we learned How to Iterate over a Two Dimensional Array in Swift language with well detailed examples.