LOOPING

These statements are used to control the flow of the program and repeat any process multiple times according to user’s requirement. We can have three types of looping control statements.

1. While

2. Do-while

3. For

While

It is an entry control loop statement, because it checks the condition first and then if the condition is true the statements given in while loop will be executed.

SYNTAX:-

Initialization;

while (condition)

{

Statements;

Incremental / decrement;

}

Do-while

Do-while loop is also called exit control loop. It is different from while loop because in this loop the portion of the loop is executed minimum once and then at the end of the loop the condition is being checked and if the value of any given condition is true or false the structure of the loop is executed and the condition is checked after the completion of true body part of the loop.

SYNTAX:-

Initialization

do

{

Statement;

Increment / decrement;

}

while (condition)

For loop

It is another looping statement or construct used to repeat any process according to user requirement but it is different from while and do-while loop because in this loop all the three steps of constructions of a loop are contained in single statement. It is also an entry control loop. We can have three syntaxes to create for loop:-


for (initialization;

Test condition; Increment / decrement)

{

Statement;

}


for (; test condition; increment / decrement)

{

Statement;

}


for (; test condition;)

{

Statement;

Increment / decrement

}



#include

void main ( )

int a;

clrscr ( );

for (a=1; a<=10; a++)

{

printf (“%d \n”,a);

}

getch ( );

}