How to use 2D array in Swift

2 Answers

0 votes
let arr: [[Int]] = [[5, 7], [2, 9], [1, 3]]

print(arr[0][0])
print(arr[0][1])

print(arr[1][0])
print(arr[1][1])

print(arr[2][0])
print(arr[2][1])



/*
run:

5
7
2
9
1
3

*/

 



answered Sep 18, 2020 by avibootz
0 votes
let arr: [[Int]] = [[5, 7], [2, 9], [1, 3]]

for i in 0...2 {
    for j in 0...1 {
        print(arr[i][j])
    }
}



/*
run:

5
7
2
9
1
3

*/

 



answered Sep 18, 2020 by avibootz
...