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 trialElena Paraschiv
9,938 PointsWhy does the program display 10 numbers if counter < 10
Shouldn't it display 9 numbers instead ?
2 Answers
Grace Kelly
33,990 PointsHi Elena, it depends on where the counter is set at, if counter = 0 and the counter < 10 then we get 10 numbers as the count STARTS at 0 and finishes at 9, like so:
<!-- the numbers on the left are 0 - 9 (counter < 10) and the numbers on the right are the number of times the loop is ran -->
0 - 1
1 - 2
2 - 3
3 - 4
4 - 5
5 - 6
6 - 7
7 - 8
8 - 9
9 - 10
hope that helps!!
Jason Anders
Treehouse Moderator 145,860 PointsNo, you will get 10 numbers because the initial variable is set at 0.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ==> 10 numbers.
I've done that a few times... we just have to remember that zero is a number. :)
Elena Paraschiv
9,938 Pointsexactly Jason :). Thanks
Elena Paraschiv
9,938 PointsElena Paraschiv
9,938 PointsYes, you are right Grace :). Just realised it when I moved to the challange and the counter was set to 1. Thanks very much for confirmation
Grace Kelly
33,990 PointsGrace Kelly
33,990 PointsNo problem!! Glad you figured it out :)