5. The for loop
The for loop allows to execute a set of
instruction until a certain condition satisfied.
EXAMPLE
For(int i=0;i<7;i++)
{
printf(“welcom for loop”);
}
6. Nested for loop
We can also use loop within loop. In nested for loop one
or more for statements are included in the body of the .
Example
For(int i=1;i<=3;i++)
{
For(int j=1;j<=2;j++)
{
printf(“n i*j:%d”,i*j);
}
}
Output
i*j=1
i*j=2
i*j=2
i*j=4
i*j=3
i*j=6
7. THE while loop
The while loop is frequently used in progrm for the
repeated execuation of satement in a loop.Until a certain
condition is satisfied the loop statements are executed.
Example
Int x=1;
While(x<5)
{
Printf(“you are begnners “);
X++;
}
Output
you are begnners
you are begnners
you are begnners
you are begnners
8. The do-while loop
A do...while loop is similar to a while loop, except the fact that it is
guaranteed to execute at least one time.
Example
#include <stdio.h>
int main ()
{
int a = 10;
do
{ printf("value of a: %dn", a);
a = a + 1;
}while( a < 20 );
return 0;
}
Output
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19