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 For Loops

Margarita Cascante Makarova
PLUS
Margarita Cascante Makarova
Courses Plus Student 3,053 Points

Problems understanding the counter

I dont' understand why soon as the value in i is 11, then the loop is finished. Is it 10?

clemhlrdt
clemhlrdt
20,534 Points
for (var i = 0; i < 10; i++) {
   // do something in here
}

Here, you start the counter of the for loop with a value of 0. Then you have the evaluation, "i<10" which means that the for loop will go on as long as i is below 10. Finally you have the increment i++ (or its equivalent i+=1). For repetition, you will add +1 to i. On the 11th time, the loop will evaluate the value of i and will stop because the evaluation will be false; i is no longer below 10.

I would also like to point out that you start at 0.