2

I am copying this very simple line of code from Apple's swift tutorial, but it generates the following error:

.. is unavailable: half open range operator .. has been renamed to ..< (strangely, .. is NOT renamed to ..<)

var firstForLoop = 0
for i in 0..3 {
    firstForLoop += i
}

I have tried adding "var":

for var i in 0..3 {
    firstForLoop += i
}

And somewhat counterintuitively, that results in "i" being unidentified! I would expect i to be unidentified in the first loop, not the second.

5
  • 1
    Well, this is pretty obvious, replace 0..3 in your code with 0..<3. Apple renamed the operator Commented Jul 24, 2014 at 9:17
  • 2
    you should use ..< instead of .., and i don't understand your question. Commented Jul 24, 2014 at 9:17
  • for number in 0..3{ try Commented Jul 24, 2014 at 9:21
  • 1
    You can download a current version of the Swift book, it has already been updated for the beta 4 release. The change is also documented in the beta 4 release notes. Commented Jul 24, 2014 at 9:37
  • I didn't know how to interpret the error message. It mentions that .. is replaced. I didn't realize that means that the operator is actually replaced in the swift language! Commented Jul 24, 2014 at 9:56

1 Answer 1

7

You are using older knowledge/documentation/code with a newer release of the Swift language. The half-closed range operator changed to ..< with the closed range operator remaining as .... Thus use:

for i in 0..<3 { /* ... */ }

In action:

> for i in 0..<3 { print (i) }
0
1
2
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.