Looping statemnets in C:

Looping statements are used to repeat the certain part of codes  until the condition becomes false. Its used to perform repetitive tasks.

Loop can be determines when looping count is constant and it can be execute certain times with the user’s inputs also.

There are three types of looping statements are there

  • While
  • Do-while
  • For


While statement:



Set of codes which needs to execute again and again until condition goes false.


Whenever while statement executes first it checks the condition. If the condition is true then it will execute the block of the statements until the condition goes false.

Example program:

Write a program to execute sum of n numbers.

Step to proceed.

First you need to get the n values from the user. Then you need to execute the loop with n times and get the sum of all the inputs and display the same.



#include <stdio.h>

int main()
    int n, sum = 0,inputval;
    printf("Enter the value of n:\n");
    printf("Enter %d values : \n",n);
    while(n > 0)
        sum = sum + inputval;
    printf("Sum of the given input is : %d\n",sum);

Do while:

Do while looping statement initially allows the code which has been  placed inside the block then it will check the condition towards the end of the block. If the condition is true then it will allow to repeat the block of the codes otherwise it will not allow the blocking code to be repeated.




set of codes inside the blocks. must exec



Try to write the program to get the sum of the digits by using do while statements.

example : 123 as input then output will be 1+2+3 = 6. Like this you need to implement.