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!
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
Quinton Dobbs5,149 Points
Why are there 10 numbers when it is 'counter < 10'?
Shouldn't 'counter < 10' come out with 9 numbers since 10 is not less than 10? Or does 0 actually count as a run through the loop?
You are correct in that the count will normally start at 0.
For example if we have a variable named "iteration" and it is set as 0 which will be used to record the number of times through the loop. Another variable named "lap" will be used to simulate a runner doing laps of an oval.
- iteration 0: lap 1
- iteration 1: lap 2
- iteration 2: lap 3
- iteration 3: lap 4
- iteration 4: lap 5
- iteration 5: lap 6
- iteration 6: lap 7
- iteration 7: lap 8
- iteration 8: lap 9
- iteration 9: lap 10
The iteration is 9 while the number of laps is 10.