Loop Control Statement

Loop Control Statement

Loop control statements are used when a section of code may either be executed a fixed number of times. C gives you a choice of three types of loop statements, while, do- while and for.

  • The while loop keeps repeating an action until an associated condition returns false. This is useful where the programmer does not know in advance how many times the loop will be traversed.
  • The do while loop is similar, but the condition is checked after the loop body is executed. This ensures that the loop body is run at least once.
  • The for loop is frequently used, usually where the loop will be traversed a fixed number of times.

The While Loop

When in a program a single statement or a certain group of statements are to be executed repeatedly depending upon certain test condition, then while statement is used. The syntax is as follows:

while (test condition)




Here, test condition is an expression that controls how long the loop keeps running.

  • Body of the loop is a statement or group of statements enclosed in braces and are repeatedly executed till the value of test condition evaluates to true.
  • As soon as the condition evaluates to false, the control jumps to the first statement following the while statement.
  • If condition initially itself is false, the body of the loop will never be executed.
  • While loop is sometimes called as entry-control loop, as it controls the execution of the body of the loop depending upon the value of the test condition.

The do…while Loop

There is another loop control structure which is very similar to the while statement – called as the do.. while statement. The only difference is that the expression which determines whether to carry on looping is evaluated at the end of each loop. The syntax is as follows:





while(test condition);
  • In do-while loop, the body of loop is executed at least once before the condition is evaluated.
  • Then the loop repeats body as long as condition is true.
  • However, in while loop, the statement doesn’t execute the body of the loop even once, if condition is false. That is why do-while loop is also called exit-control loop.

The for Loop

for statement makes it more convenient to count iterations of a loop and works well where the number of iterations of the loop is known before the loop is entered. The syntax is as follows:

for (initialization; test condition; increment or decrement)




The main purpose is to repeat statement while condition remains true, like the while loop. But in addition, for provides places to specify an initialization instruction and an increment or decrement of the control variable instruction. So this loop is specially designed to perform a repetitive action with a counter.

  • Initialization is executed. Generally it is an initial value setting for a counter variable. This is executed only once.
  • Condition is checked, if it is true the loop continues, otherwise the loop finishes and statement is skipped.
  • Statement is/are executed. As usual, it can be either a single instruction or a block of instructions enclosed within curly brackets { }.
  • Finally, whatever is specified in the increment or decrement of the control variable field is executed and the loop gets back to step 2.

Various forms of loop statements can be:

(a) A blank first statement will mean no initialization.



(b) A blank last statement will mean no running increment/decrement.

for (initialization;condition;)


(c) A blank second conditional statement means no test condition to control the exit from the loop. So, in the absence of second statement, it is required to test the condition inside the loop otherwise it results in an infinite loop where the control never exits from the loop.

for (initialization;;increment/decrement)


(d) Initialization is required to be done before the loop and test condition is checked inside the loop.

for (;;increment/decrement)


(e) Test condition and control variable increment/decrement is to be done inside the body of the loop.

for (initialization;;)


(f) Initialization is required to be done before the loop and control variable increment/decrement is to be done inside the body of the loop.

for (;condition;)


(g) Initialization is required to be done before the loop, test condition and control variable increment/decrement is to be done inside the body of the loop.

for (;;;)


Related Post

Switch Case Statement Switch Case Statement The switch statement is a multi-way branch statement. It provides an easy way to dispatch execution to different parts of c...
Asset Color Catalog | Swift Tutorial Asset Color Catalog is the feature of XCode 9. BY the use of this feature we can maintain the colors easily and avoid the mistakes. We can create the ...
Comments in C Comments in C Comments in C language are used to provide information about lines of code. It is widely used for documenting code. There are 2 types o...
Firebase Push notification | Swift tutorial Push Notification by firebase in IOS.For Firebase Push notification we need to have paid apple developer account. You need to Enroll into the Apple D...
C Language – Introduction Why C? There are three important aspects of any language so as C has : The way it stores data, The way it operates on this data and How th...
Decision Control Statement C has three major decision making instructions— the if statement, the if-else statement, and the switch statement. The if Statement It is used to ex...

Leave a Reply

Your email address will not be published. Required fields are marked *