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 trialPaul Henry
2,125 PointsIn the for loop...
So we have
for (int i = 0; i < jacksons.length; i++)
Why wouldn't the loop stop before the last item in the array, if "i" must be less than the length of the array?
2 Answers
Kristian Gausel
14,661 PointsBecause arrays are 0 indexed, so an array of length 5: [0, 1, 2, 3, 4,] (it has 5 elements, which is the length) Has the indexes i put as values in the array. Therefore you want to check the indexes from 0 to length - 1
Quinton Rivera
5,177 Pointsyou start counting from 0 not 1 with arrays