Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

++ not a binary operator

for var i = 0; i < todo.count; i++{ // this gives an error : not a known binary operator
   print(todo[i])
    i++
}

When i change it to:

for var i = 0; i < todo.count; i+1{ // now it does work
   print(todo[i])
    i++
}

howcome ++ is not valid? other languages also do it like this, is this new in swift or something? the example in the video also do ++

3 Answers

Hi Chris,

You just have to add a space after the ++ to make your code work like this.

for var i = 0; i < todo.count; i++ { // this gives an error : not a known binary operator
    print(todo[i])
    i++
}

I hope that helps,

Mike

PS: Thanks to the awesome resources on Team Treehouse, I just launched my first app. :-)

Code! Learn how to program with Swift

looks cool Michael

Hi Chris,

If you add a space between the i++ and the curly brace, it should work just fine.

Steve.

man, that was stupid :D thanks guys

Hey, no problem! :-)