when I modify string or another variable inside the loop it's condition is rec开发者_开发知识库alculated each time? or once before the loop start
std::string a("aa");
do
{
a = "aaaa";
}
while(a.size<10)
and what about for loopEvery time. Basically it checks every time to see if the statement inside the conditional is true. If it is true, continue to loop, if it is false break the loop. That is why these constructs are called Conditional Loops
imagine what would happen if condition is not recalculated. then if that was true to begin with it would never change and you will get an infinite loop.
having said that in your case the condition is always true (because string length doesn't change).
Do ... while loops will check the condition every time AFTER the inside of the loop has been executed.
For loops will check the condition every time BEFORE the inside of the loop has been executed.
精彩评论