← Previous Next →


 Loop control statements in C are used to perform looping operations until the given condition is true.
Control comes out of the loop statements once condition becomes false.

There are 3 types of loop control statements in C:

  • for
  • while
  • do-while

For 

Syntax:

for( initialization ; condition ; expression) 
{
        // code
}

 initialization : setting initial value of variable

condition : loop will run till this condition is true

expression : Expression is executed at last of each loop (like - increment/decrement)


While

Syntax: 

while(condition) 
{
  // code
}   

condition : this loop will run till condition is true Syntax:


Do- While

Syntax:

do 
{
  // code 
} while(condition);

this loop will be executed till condition is true.


Note:

Differnce between while and do..while loop is in do..while loop
atleast one time loop will run since it check condition after code is executed.


Loop Control Statements

Loop control statements change execution from its normal sequence. C supports the following control statements.

  • break statement
  •   Terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch.
  • continue statement
  •    Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.
  • goto statement
  •    Transfers control to the labeled statement.
← Previous Next →