do-while


do-while Statement

This is an exit control loop structure. Here the statement block is executed first and then the condition is tested. If the condition is true, the statement block is executed once again. This process continues until the condition becomes false. When once the condition is false, the control will come out of the loop. i.e., all the statements that are enclosed between do-while are executed at least once even if the condition is false at first time.

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



                  
Sample Program for printing numbers from 1 to 100

void main()
{
 int i;
 i=1;
do 
{
  printf("\t%d",i);
  i++;
 }
 while(i<=100);
}

Note:- Here i is knownas loop-control variable.

No comments:

Post a Comment