Friday, June 1, 2012

Looping Control Structures




In C Language We have three types of loops
  1. while loop: it is a precondition loop, first of all it checks the condition if the condition is true it executes the looping statements and incrementation / decrementation will done and again it check the condition.
    Syntax: intilization;
    while (cond)
    {
    statements;
    inc/dec;
    };
  2. do while loop: it is a post condition loop, First of all looping statements will be executed than it checks the condition if the true it enters into the loop other wise it come outside from the loop.
    Syntax: intilization;
    do
    {
    statements;
    inc/dec;
    }
    while(cond);
  3. for loop: it is same as while loop and it is a precondition loop. In for loop all the 3 statements are written in a single line. i.e. intilization, condition, incrementation/decrementation.
    Syntax: for(inti;cond;inc/dec)
    {
    statements;
    }

No comments:

Post a Comment