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
chrisverra
3,760 Points++ 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
Michael Reining
10,101 PointsHi 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. :-)
Steve Hunter
57,712 PointsHi Chris,
If you add a space between the i++ and the curly brace, it should work just fine.
Steve.
chrisverra
3,760 Pointsman, that was stupid :D thanks guys
Steve Hunter
57,712 PointsHey, no problem! :-)
chrisverra
3,760 Pointschrisverra
3,760 Pointslooks cool Michael