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 trialJose Estrella
1,529 PointsI don't get this loop, some help please
both answers for the quiz are similar one is
for(int i = 0; i < 5; i++);
the other
for(int i = 1; i < 5; i++);
why is the first one correct and loops?
4 Answers
Derek Medlin
6,151 PointsIn the first example, "i" was initialized with the value of 0 and in the 2nd example, "i" was initialized with the value of 1. So after the first irritation, the value of "i" gets incremented by 1 (hence i++). Since the value of "i" is already 1, "i" will have the value of 2 the 2nd time around. After 4 irritations "i" will be equal to 5 so the loop will stop.
Ludwing Najera
4,596 Pointshave you used arrays?
Jose Estrella
1,529 Pointsyes but this is the question asking for the answer that loops 5 times, wouldn't they both loop to 5?
Jose Estrella
1,529 PointsJose Estrella
1,529 PointsThank you so much! both of you for your time i understand it now