2. FOR LOOP
The syntax of for loop is
for(initialisation;condition checking;increment)
{
set of statements
}
The Example for for loop:
// Program to print Hello 10 times
for(i=0;i<10;i++)
{
printf(“Hello”);
}
3. WHILE LOOP The syntax for while loop
while(condition)
{
statements;
}
4. Example for while loop:
a=10;
while(a != 0)
{
printf(“%d/t”,a);
a- -;
}
Output:
10 9 8 7 6 5 4 3 2 1
5. DO WHILE LOOP The syntax of do while loop
do
{
set of statements
}while(condition)
6. Example of do-while loop:
i=10;
do
{
printf(“%d/t”,i);
i--;
}while(i!=0)
Output:
10 9 8 7 6 5 4 3 2 1
7. Example of do-while loop:
i=10;
do
{
printf(“%d/t”,i);
i--;
}while(i!=0)
Output:
10 9 8 7 6 5 4 3 2 1