Iterate over two arrays simultaneously

You can use zip(), which creates
a sequence of pairs from the two given sequences:

let strArr1 = ["Some1", "Some2"]
let strArr2 = ["Somethingelse1", "Somethingelse2"]

for (e1, e2) in zip(strArr1, strArr2) {
    print("\(e1) - \(e2)")
}

The sequence enumerates only the “common elements” of the given sequences/arrays. If they have different length then the additional
elements of the longer array/sequence are simply ignored.

Leave a Comment