Hello guys, I have a quite basic question but actually I do not how to approach the problem.
Given two arrays
I want to loop over the two arrays such as the output is like:
Any help is appreciated.
Dennis
Given two arrays
The first one with n items
Code Block swift arrayOfItems = ["1", "2", "3", "4", "5", "6", ..., "n"]
The second one with 5 items
Code Block swift arrayOfFive = ["Item1", "Item2", "Item3", "Item4", "Item5"]
I want to loop over the two arrays such as the output is like:
Code Block 1 Item_1 2 Item_2 3 Item_3 4 Item_4 5 Item_5 6 Item_1 7 Item_2 . . .
Any help is appreciated.
Dennis
When will the loop finish? When arrayOfItems is finished? Or a longer Array finished? Or else you want an infinite loop?
In case When arrayOfItems is finished:
(Assuming arrayOfFive is not empty.)
In case When arrayOfItems is finished:
Code Block for i in arrayOfItems.indices { let elt1 = arrayOfItems[i] let elt2 = arrayOfFive[i % arrayOfFive.count] print(elt1) print(elt2) print() }
(Assuming arrayOfFive is not empty.)