|
Answer» The syntax of a while loop in C++ is: while(condition) { statement(s); } - Here the condition may be any expression, and true is any nonzero value. The loop iterates while the condition is true.
- When the condition becomes false, program control passes to the line immediately following the loop.
- During the first attempt, when the condition is tested and the result is false, the loop body will be skipped and the first statement after the while loop will be executed.
Syntax of do-while loop do { statements; } while (condition); - Here control enters into the body of loop without checking any condition initially and loop iterates while the condition is true at the end.
- When the condition becomes false, program control passes to the line immediately following the loop.
- During the first attempt, no condition is tested at the beginning and checked only at the end and by that time one time the body of loop is executed at least one time.
|