Re:Why do arrays start at 0?
by gernb on Thursday August 25, 2022 @04:29AM
(#32591115)
doesn't swift use inclusive indexing? 1...10 includes 10
[ Parent
| on HN ]
Re:Why do arrays start at 0?
by maxdamantus on Thursday August 25, 2022 @04:51AM
(#32591244)
Haven't used Swift, but looking at the documentation, it seems to support `...` for end-inclusive and `..<` for end-exclusive.
Looking at the Swift standard library, end-exclusive ranges seem to be far more commonly used:
~/build/swift$ git grep -e '\.\.< *[a-zA-Z0-9_(]' --and --not -e '^ *//' -- stdlib/\*.swift | wc -l
599
~/build/swift$ git grep -e '\.\.\. *[a-zA-Z0-9_(]' --and --not -e '^ *//' -- stdlib/\*.swift | wc -l
112