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

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops Exiting Loops

You use the increment operator i++; in one of the questions without using or explaining it beforehand.

I questioned on an earlier video why you had not introduced the increment and decrement operators and I have just noticed that it appears in one the questions following this video without ever being mentioned or explained beforehand.

I also want to comment Phil that even a year later the video hasn't been edited to explain that. I see that as quite a problem: introducing new syntax by accident without explaining it, but then with student feedback not changing the video content to fix it.

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

I've not seen the ++ or -- operators in loops yet, and I agree it's not usual (certainly in my own experience) to use += to increment in loops. I think it's down to personal preference in real life projects.

Just know that += 1 and ++ do the same thing. They perform calculations on integer values adding to a variable by 1.

One advantage of += is the ability to increment by a value other than 1, e.g. +=2. or being able to increment after the loop has completed so as to be able to use the counter to keep track depending on the circumstance, e.g. =+1. ++ and -- are simply used to save time. don't yo think.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Absolutely. My point was I don't usually see ++ or -- used in Treehouse videos, mainly because the examples shown are about counting in more than one increment. Much more exciting than the typical "loop a counter to 10" example you often see elsewhere. :-)

Bruno Dias
Bruno Dias
10,554 Points

Thank you guys for clarifying!