Skip to content

Instantly share code, notes, and snippets.

@ajaysinghthakur
Created September 16, 2021 08:32
Show Gist options
  • Save ajaysinghthakur/d51f80151d0c78cdf3efc246906e879a to your computer and use it in GitHub Desktop.
Save ajaysinghthakur/d51f80151d0c78cdf3efc246906e879a to your computer and use it in GitHub Desktop.
Iterate an array from the any index then the beginning, can transverse array all element from any starting index
let a = [1,2,3,4,5,6]
let startIndex = 5
let endIndex = a.count
for i in stride(from: 0, to: endIndex, by: 1) {
let newIndex = (i + startIndex) % endIndex
print(newIndex)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment