Menu

DO WHILE LOOP in C Programming

  • Do while loops are useful for things that want to loop at least once.
  • The do while statement is used less often than the other structured loop statements (for and while).
  • It is an exit controlled loop.

Syntax:

     Initialization expression
     do{
          loop-body;
          Updation expression;
     }while (Test Expression) 

Description:

  • First the initialization expression will be evaluated.
  • Then execute loop body and update the expression.
  • Then only evaluates the test expression.
  • If it is true,the loop body works again.
  • This process will continue untill the test expression becomes false.
  • Here the updating statement will be placed within the body of loop.

Example

     #include
     main()
     {
       char ch='A';
       do{
         printf("	%c",ch);
         ch=ch+1;
      }while(ch<='Z');
     }

Output:  A B C D E F G H I J K L M N O P Q R S T U V W X Y Z