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 trial

iOS Objective-C Basics (Retired) Functional Programming in C Loops

Jose Estrella
Jose Estrella
1,529 Points

I 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

In 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.

Jose Estrella
Jose Estrella
1,529 Points

Thank you so much! both of you for your time i understand it now

Jose Estrella
Jose Estrella
1,529 Points

yes but this is the question asking for the answer that loops 5 times, wouldn't they both loop to 5?