The C while loop statement allows a code block to be run repeatedly until a condition is met. This tutorial guides you on how to use "while loop" in the C program.



The while loop is the most basic loop in C programming; it has a control condition and executes as long as the condition is true. The loop's condition is tested before executing the code block inside it, so it is called an entry-controlled loop.

The basic format of the while loop statement is:

Syntax:

While (condition)
{
   statement(s);
   Incrementation;
}

Figure - Flowchart of while loop:

c-while

Example of a C Program to Demonstrate while loop

Example:

#include<stdio.h>
 
int main ()
{
   /* local variable Initialization */
   int n = 1,times=5;

   /* while loops execution */
   while( n <= times )
   {
      printf("C while loops: %d\n", n);
      n++;
   }
 
   return 0;
}

Program Output:

c-while-loop


C while loops - Video Tutorial

Please watch this video tutorial to understand "C while loops" in depth.



Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram