LOOPS
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”);
}
WHILE LOOP The syntax for while loop
while(condition)
{
statements;
}
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
DO WHILE LOOP The syntax of do while loop
do
{
set of statements
}while(condition)
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
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

Looping in C

  • 1.
  • 2.
    FOR LOOP The syntaxof 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 Thesyntax for while loop while(condition) { statements; }
  • 4.
    Example for whileloop: a=10; while(a != 0) { printf(“%d/t”,a); a- -; } Output: 10 9 8 7 6 5 4 3 2 1
  • 5.
    DO WHILE LOOPThe syntax of do while loop do { set of statements }while(condition)
  • 6.
    Example of do-whileloop: 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-whileloop: i=10; do { printf(“%d/t”,i); i--; }while(i!=0) Output: 10 9 8 7 6 5 4 3 2 1