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 Review while loops, do...while loops, and Loop Conditions

Amber Hoddinott
Amber Hoddinott
6,494 Points

doesnt the do while loop need to be less then or equal to 10 to run 10 times?

?

2 Answers

Colin Marshall
Colin Marshall
32,861 Points

The counter starts at 0 and doesn't get incremented until the end of the loop. If it is set to less than or equal to 10, it will print it out 11 times because the loop runs for 0-10, which is 11 values.

pi R
pi R
12,720 Points

Nope, because the do..while loop execute the code once before evaluating the condition ! So if you put equal to 10, it will run 11 times.