Roee84 Roee84 - 1 year ago 51
Swift Question

Replacement for c style loop with modulo

Since C-style for statement is deprecated and will be removed in a future version of Swift, what is the best way to achieve the following:

for var i = startIndex; i != endIndex; i = (i + 1) % arrCount {

(I want to iterate the array, but start from somewhere at the middle and continue until I'll reach the index I started from)

startIndex > endIndex

Avt Avt
Answer Source

"while" should be the best:

var i = startIndex
while i != endIndex {
    i = (i + 1) % arrCount