while loop

Loops are used to execute a set of statements repetitively. The number of times to repeat the loop is decided by a condition. C provides three kinds of looping statements. The simplest among them is the while loop.

while loop is written in the form

while (condition)

while loop will evaluate a condition at the beginning of the loop. If the condition is true, the block of statements between the curly braces is executed. The condition is evaluated again and the loop is repeated if the condition is still true. This process continues until the condition evaluates to false or 0.


Here is an example of a program that prints the numbers from 1 to 10 using while loop.

#include <stdio.h>

int main() {
int num;
while (num <= 10) {
printf("%d \\n",num);

return 0;
Last Updated: 07-June-2013

Post a comment


Your Comment

Email (We dont publish it)


Nothing yet..be the first to share wisdom.