Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
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.