+3 votes
in Class 12 by kratos

Illustrate with the help of syntax, differences between While and Do-While looping statements in C++.

1 Answer

+3 votes
by kratos
 
Best answer

The syntax of a while loop in C++ is:

while(condition)

{

statement(*);

}

  • 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 ****.

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 **** at least one time.
...