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
Bryan Elliott
6,835 PointsHelp me understand the ++ operator
I'm writing while loops and I'm needing to add ++ to index. I know that it stops the while loop from turning into an infinite loop but I do not understand the logic behind it. can someone please explain ?
var todo : [String] = ["Return calls", "Write blog", "Cook dinner","Pickup Laundry", "Buy bulbs"]
var index = 0
while index < todo.count { println(todo[index]) index++ }
1 Answer
Ryan Field
Courses Plus Student 21,242 PointsHi, Brian. Basically, the ++ operator takes whatever variable you use it with and adds 1 to its value. It's short hand for x = x + 1 or x += 1.