Loop Control Statements in C | for, while, do-while loop

Loop Control statements are used to execute and repeat a block of statements depending on the value of a condition. There are three types of loop control statements or structures used in C language.

  • for loop
  • while loop
  • do-while loop
  • 1. for loop : A for loop is used to execute and repeat a block of statements depending on a condition. It has the following syntax :

    for(<initial value>;<condition>;<increment>)
    {
      - - - - - - - - - - 
       <statement block>
      - - - - - - - - - -
    }
    

  • Nested for loop : This statement block of a for loop lies completely inside the block of another for loop that is called Nested for loop or Nested for Statement.
    for(i=1;i<=3;i++) // outer loop
    {
     - - - - - - - - 
     for(j=1;j<=5;j++) // inner loop
     {
     - - - - - - - - 
     <statement block>
     - - - - - - - -
     }
    }
    

    2. while loop : A while loop is used to execute and repeat a block of statements depending on a condition. It has the following syntax :
    while(<condition>)
    {
      - - - - - - - - 
      <statement block>
      - - - - - - - - 
    } // where <condition> is a relational or logical expression which will have the value true or false.
    

    3. do-while loop : A do-while loop is used to execute and repeat a block of statements depending on a condition. It has the following syntax :
    do
    {
      - - - - - - - - 
      <statement block>
      - - - - - - - - 
    }
    while(<condition>) // where <condition> is a relational or logical expression which will have the value true or false.