Skip to content

Instantly share code, notes, and snippets.

@dennisvennink
Forked from mattt/BoundedSequence.swift
Last active June 16, 2019 06:03
Show Gist options
  • Save dennisvennink/afeb1bbb7d7554516f97db956c6974a0 to your computer and use it in GitHub Desktop.
Save dennisvennink/afeb1bbb7d7554516f97db956c6974a0 to your computer and use it in GitHub Desktop.
let xs = [1, 2, 3, 4, 5]
for (element, index) in zip(xs, xs.indices) {
if index == xs.startIndex {
print("START")
}
print(element)
if index == xs.index(before: xs.endIndex) {
print("END")
}
}
// Prints: "START\n1\n2\n3\n4\n5\nEND\n"
@anthonycastelli
Copy link

Line 10 should read index == xs.index(before: xs.endIndex)

if index == xs.index(before: xs.endIndex) {
    print("END")
}

@dennisvennink
Copy link
Author

Thank you, I missed that one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment