Home / Programs / while loop in C Programming
Programming Example

while loop in C Programming

👁 5,895 Views
💻 Practical Program
📘 Step by Step Learning
This program will print 10 to 19 using while loop

Program Code

#include <stdio.h>
 
int main () {

   /* local variable definition */
   int a = 10;

   /* while loop execution */
   while( a < 20 ) {
      printf("value of a: %d\n", a);
      a++;
   }
 
   return 0;
}

Output

value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
Press any key to continue . . .

Explanation

A while loop in C programming repeatedly executes a target statement as long as a given condition is true.

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.