Doubt with creation of For on Swift 3

Asked

Viewed 136 times

0

I’m following an iOS course and in the course shows the for in this way:

for var i = 1; i <= 10; i++ {

}

But I have an error message, has it changed? How could this be done in the new way?

error: Creatureloop.playground:6:1: error: C-style for statement has been Removed in Swift 3

  • It has. That’s one for that came from C. The IDE is saying that you have a better way to do it and that you should follow the language with its syntax. https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/ControlFlow.html

1 answer

0

Will print from 1 to 10

for i in 1 ... 10 {
    print(i)
}

Will print from 1 to 9

for i in 1 ..< 10 {
    print(i)
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.