Loop Statements

The looping statements are used to execute group of statements repeatedly until some condition is satisfied. The looping structures are

While structure

Do...while structure

For structure

While structure

This is a simple looping statement when executed, the computer first evaluates the test condition. The control is transferred to next statement if the value is false. The body of the loop is executed repeatedly until the test condition becomes false. The control is transferred to the next statement when the test condition becomes false.

while(test condition)

{

body of the loop;

}

next statement;

Example:

#include

main ()

{

int j;

j=1;

while (j<5)

{

printf(“welcome”);

j++;

}

}

Do...While structure

When this statement is executed the body of the loop is executed first. The test condition is then evaluated. The control is transferred to the next statement, if the value is false. The body of the loop is executed repeatedly until the test condition becomes false. The control is transferred to the next statement if the test condition becomes false.

The general form is

do

{

body of the loop;

}

while(test condition);

next statement;

Example:

#include ,stdio.h>

main()

{

int j;

j=1;

do

{

printf(“welcome”);

j++;

}

while(j<5)

}

For statement

If the group of statement executed for known number of times then we can use for statement. The general form is