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.

bg
217 PointsQuestion on "do" loop
int i = 1; do { printf("looping %d", i); } while ( i < 1 );
Why wouldn't it loop through zero times, since i is set to 1 (it's not less than 1)?
2 Answers

John W
21,558 PointsWhen using a do { ... } while(...);
syntax, the test for termination is performed at the end of each loop. Thus even if it starts off with the right condition to terminate, a single round of execution would still go before any test for termination. This is in contrast with the while(...){ ... }
syntax, which performs the test before each loop.

bg
217 PointsThanks so much, John!