-->

do while loop


Do while Loop

            The do-while loop is similar to the while loop except that the conditional expression is tested at the end of the loop. The do-while statement executes the block of statements within its braces as long as its conditional expression is true. When you use a do-while statement, the condition is tested at the end of the do-while loop. this means the code will always be executed at least once.
Syntax
do
{
   staement // Body of do while
}
while(condition);
 note: Do while is also called exit loop

Flow chart




#include <stdio.h>

int main () {

   /* local variable definition */
   int a = 10;

   /* do loop execution */
   do {
      printf("value of a: %d\n", a);
      a = a + 1;
   }while( a <6  );

  
}
Out put
value of a: 1
value of a: 2
value of a: 3
value of a: 4
value of a: 5


No comments:

Post a Comment

Basic structure of c program