What is the purpose of do…while statement? How dose it differ form the while statement?
do-while statement or do-while loop
The purpose of do…while statement/loop is
A do-while loop is used to execute and repeat a block of statement depending on a condition. It has the following form.
where <condition> is a relational or logical expression which will have the value true or false.
i = 1;
s = s + i ;
p = p * i ;
while (i <= 10);
When this statement is executed, the computer will execute the statement block irrespective of the value of the condition. At the end of the statement block, the condition is evaluated. If the value of the condition is true the statement block is executed again and is repeated until the condition fales.
A while loop is used to execute and repeat a statement block depending on a condition which is evaluated at the beginning of the loop that’s why while loop differs from a do-while loop