While Statement in C Programming

“while loop” repeats a set of statements if condition is true. If condition is false the flow of control do not enter inside of while loop.

It first tests the condition then execute the body of loop.

Syntax of a while statement−

Example: Write a program to print 1 to 10 using while loop.

OUTPUT

Description: In the above program, line “while( a <= 10 )” will check if condition is true or false.

In the above case when a=1, condition is true and flow of control move inside of while and print 1 after that increment occurs.

Now a=2, again condition is true and flow of control move inside of while and print 2 after that increment occurs.

Now a=3, again condition is true and flow of control move inside of while and print 3 after that increment occurs.

This process is continue until condition is false(in this case condition false occur when a=11).

Example: Write a program to print 10 to 1 using while loop.

OUTPUT