The while loop is used when you want to execute a single line statement or block of statements repeatedly with checkd condition before making an iteration.
The syntax is:-
while ( condition ) {
statement 1; } |
Suppose we want to print 1 to 10 numbres on display, what to do?
One way is to write 10 number of printf() function in C program but if numbers are too big like 1 to 1000, C provides one another way to print by using single printf()
that is called loops, See example below:-
#include<stdio.h> int main() { int count = 0; while (count <= 10)
printf(“%d \t”,count); } } When you compile and execute above C program, this will print 0 to 10 numbers. here ‘\t’ is used to place a tab space between two numbres, Explanation :- |