Looping



Loops are used to repeatedly execute a block of code. Some times in ‘C’ we don’t want to execute the same instruction which is already executed again & again.

In such scenario, the control has to be taken back to previous statements which are already executed. Taking control back to previous statement is known as looping.

C provides us three different looping structures:-

  • for loop.
  • while loop.
  • do while loop.
  • Nested loops
For Loop

The for loop statement is the first& perhaps the most commonly is used looping statement in C.

The general form is:
for (initiazation_expression; test condition; increment/decrement operation)
   {
       Statement 1;
       Statement 2;
       -
       -
       -
       Statement n;
   }

Ex: for(int i=0;i<10;i++)

Flow chart of nested if else
for loop