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

if there is no i++, wouldnt it go on forever?

why isnt it infinite?

2 Answers

I assume you're asking about the do-while loop in this quiz (sorry for not being able to deep link to a specific question in the forums):

int i = 1;
do {
} while ( i < 1 ) ;

In this case the loop will execute the print statement once before checking the conditional. Since the conditional will be false (1 is not less than 1) it won't execute a second time.

Petar Zelenovic
Petar Zelenovic
11,356 Points

The only thing the outcome depends on is how you set up the condition.

If your loop checks whether "true equals true" before every iteration it will continue to execute forever. After that it only boils down to the particular language syntax, and the type of the loop you're using.