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.

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?