do-while loop – free C programming tutorial

In this tutorial you you will be familiarize with one of the iteration statement that is do-while loop which is available in C programming language, along with its syntax and example.

Iteration statement

Iteration statement is defined as the set of instructions that are repeated in a sequence for specific number of times until the condition is satisfied.

When the first set of instructions is executed again, it is called an iteration.

Iteration statements are commonly known as loops.
Also the repetition or iteration processes in C programming language is done by using loop control instruction.


do-while loop statement :

The while loop statement is also known as exit control loop  as it first compiles and executes checks the inner body then condition is checked .

The while-loop statement has the following syntax:

while (expression)
   {
      statement;
      // or {block of statements}
   }

Example program of do-while loop in C:

A code in C language to determine table of any entered number by user which is less than 100 using iteration.

// Header file which contains functions for standard input and output manipulative operation.
 #include <stdio.h> 
// Compiling of code start from main function   
 int main()  
{ 
// Declaration of local variable of data-type int
    int num,i=1;

// To display on console screen 
   printf(“Enter any number…… /n ”);

 // To get input from user 
   scanf(“%d”,&num);

// to check whether the entered number is lesser than 100 or not
   if(num <= 100)
     {
// i is counter variable
        do 
          {      
             printf(“%d/n ”,num*i); 
             i++;
          }
         while(i>0)
  return 0;
}

After compilation and execution of code written above you will get the following output :

OUTPUT :

Enter any number……5
5
10
15
20
25
30
35
40
45
50

This article is contributed by ayushi kumawat.
This is all about the one of the iteration statement that is do-while loop statement which is available in C programming language, along with its syntax and example.
If you have any query please comment below or leave a mail to us.

Leave a Comment

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