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

John McDermott
John McDermott
1,417 Points

How many times will the following loop execute? Is the answer correct?

I'm confused about how the answer to this question is "once".

How many times will the following loop execute? int i = 1; do { printf("looping"); } while ( i < 1 ) ;

If i=1 then i<1 is never true. Therefore, I don't understand how the printf("looping"); can be executed. Why is the answer not "never" or "zero"? Thanks for the help.

1 Answer

Joe Timmons
Joe Timmons
4,331 Points

This is a do/while loop. The "Do" part is executed before the "While" condition is checked. This means it will always execute at least one time and continue to loop as long as the condition is true.

Hope that helps!

-Joe