Explain the Do - While Statement - Computer Programming?
A do - while loop is an exit controlled loop and the body of the loop gets executed at least once if the condition is not satisfied.
The universal form is
do
{
statements;
}
while(expression);
While the control reaches the do statement the program proceeds to evaluate the body of the loop first At the end of the body of the loop first and At the end of the body of the loop the while statement is evaluated. If the condition is true after that the body of the loop will be executed again. This will go on until the condition becomes false.
This is very alike to the while loop except that the test occurs at the end of the loop body. This guarantees that the loop is executed at least once before continuing. Such a setup is often used where data is to be read. The test after that verifies the data, and loops back to read again if it was unacceptable.
do
{
printf("Enter 1 for yes, 0 for no :");
scanf("%d", &input_value);
}
while (input_value != 1 && input_value != 0);