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 trialkabir k
Courses Plus Student 18,036 PointsWhat exactly do the pre-check and post-check mean?
In the previous two videos, he said the while loop is a pre-check construct and the do while loop is a post-check construct.
I don't wanna be making assumptions here but what exactly do pre-check and post-check mean in regard to these loops?
2 Answers
Adam Sommer
62,470 PointsAh, I guess iterator isn't quite the right word. The correct term would be the check condition. Meaning you could have a boolean value being checked and until it is a certain value the while loop will continue.
As an example:
do {
statement(s)
} while (expression);
The (expression) after the while won't be evaluated until all the code inside the curly braces has been executed. That means this do while loop is a post-check example.
A pre-check looks like:
while (true){
// your code goes here
}
The check condition is at the beginning.
Hope that clears some things up... I get still mixed up with while loops and for loops and end up usually sticking with a good old for loop.
Let me know if there's anything else I can help with.
Adam Sommer
62,470 PointsSo the pre-check means that the loop iterator variable is checked before the code inside the loop is executed and the post-check means that the iterator is checked after the code in the loop is run.
With the post-check method the code is run at least once. This may, or may not, be what you want to happen.
Hope that clears things up a little.
kabir k
Courses Plus Student 18,036 PointsYes, thanks. One more thing.
What's an example of the loop iterator variable for the While Loop and the Do While Loop shown in the videos?
kabir k
Courses Plus Student 18,036 Pointskabir k
Courses Plus Student 18,036 PointsThanks, Adam. That would be it.