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

Why don't you add a semicolon for the i variable counter at the end?

I noticed that at the end of the for loop that you don't include a semicolon for the "i" counter variable. However, you add a semicolon after each one that comes before.... why?

for (var i = 0; i < 10; i+=) {
   *code*;
}
reza sajadian
reza sajadian
718 Points

Sorry, are you talking about my code in Python?

edited code for formatting.

3 Answers

It's redundant. The () represent the beginning and end of the code statement. A semicolon is used to separate each expression. the last expression doesn't need a semicolon because there is nothing else in the statement.

Thanks, bud

yeah man, any time.

Sorry, I wasn't clear on that. I'm referring to JavaScript for loops.

reza sajadian
reza sajadian
718 Points

So, I mean, are we on the same boat? , or something is going wrong? because I haven't had any relation with java! :)