I am having trouble understanding why in this code snippet the “Hello” statement is not
being printed. I thought that the condition statement in the for loop starts getting tested after only at the second iteration.
for ( count = 0; count < 0; ++count)
{
cout<<"Hello!\n";
}
It never enters the loop at all because
forloops are tested at the start.You start with
count = 0, but the loop condition iscount < 0. So it fails right away and skips the entire loop.do-whileloops are the ones that are tested at the end of the iteration.