C'Language - [Post-tested Loop]

♠ Posted by Unknown in at 00:18

Post-Tested [Exit-Controlled] Loop:

do..while Loop:

In do..while loop construction start at do statement, the program to evaluate the body of the loop first. At the end of the loop, the test condition in the while statement is evaluated. If the condition is true, the program continues to evaluate the body of the loop Once again. This process continues as long as the condition becomes false, the loop will be terminated and the control goes to the statement that appears immediately after the while statement.

Syntax :-
           do
           {
              body of loop
           }while(test-condition);

since the test condition is evaluated at the bottom of  the loop, the do while condition provides an "exit controlled loop" and therefore the body of the loop is always executed at least once.

Example:-

main ()
{
  int a;
  a = 1;

  do
  {
      printf(" % d \n ", a);
      a = a + 1;
   }while (a<=10);
          
     getch();
     return;
}

0 comments:

Post a Comment