Loops in C



Loops in C - Definition and Usage

  • In C- Programming the control statement is used for performing looping operations until the given condition is true.
  • Control comes out of the loop statements once condition becomes false.
  • C loops execute a block of commands for the specific number of times, until a condition is met or satisfied.
  • In C-program, there are three different types of control statement as follows:
C Loop Statement

While loop Statement :

  • In C – Programming the while Loop is executed, only when condition is true.

C Syntax

While (condition)
{
    statements;
}
                        

Do While Loop Statement :

  • In C – Programming the do while Loop is executed at least one time then after executing the while loop for first time, then condition is checked.

C Syntax

do 
{
    statements; 
}
while (condition);
                        

For Loop Statement :

  • For loop is used to execute a set of statements repeatedly until a particular condition is satisfied. We can say it as an open ended loop. General format is,

C Syntax

for(initialization; condition ; increment/decrement)
    {
        statement-block;
    }
  • In for loop we have exactly two semicolons, one after initialization and second after condition.
  • In this loop we can have more than one initialization or increment/decrement, separated using comma operator.
  • for loop can have only one condition.

View More Quick Examples


Related Searches to C Loop Statement