How to print array values and indexes using for loop in Swift

1 Answer

0 votes
let arr = ["swift", "c", "c++", "php", "java"]

for i in arr.indices {
    print("\(i) - \(arr[i])")
}




/*
run:

0 - swift
1 - c
2 - c++
3 - php
4 - java

*/

 



answered Sep 3, 2020 by avibootz
...