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
Rodrigo Chousal
16,009 PointsHow many times will the following loop execute?
int i = 1;
do {
printf("looping");
}
while ( i < 1 ) ;
Wouldn't this be zero?
1 Answer

Pol Martin
8,200 PointsHi Rodrigo, the loop will execute one single time.
The DO WHILE loop will execute always at least once. That's because it first executes the block of code and evaluates the condition in the "while" part after, deciding then if it must loop again or not.
It would be zero if you used a WHILE loop instead of the DO WHILE so it would evaluate the condition before executing any of the inner code.
Here's a graphical representation for better understanding: