+1-617-874-1011 (US)

  +44-117-230-1145 (UK)

The do while loop

The syntax of Do-While Loop is:

do
{
this;
and this;
this too;
…..
etc;
}


while (if the condition is true)

In Do-While Loop the statements are evaluated first and then the conditions are checked.

In While Loop if the condition fails to satisfy then the statements will not be executed however in Do-While Loop, it will be evaluated once even if the condition fails.

/* Program to illustrate the do while loop*/

#include < stdio.h >
void main()
{
char inchar;
do
{
printf(“Input Y or N”);
scanf(“%c”, &inchar);
}
while(inchar!=’y’ && inchar != ‘n’);

if(inchar==’y’)
printf(“you pressed u\n”);
else
printf(“You pressed n\n”);
}


homework help with do while loop

Topics in C Programming