While loop is also known as a pre-tested loop. In general, a while loop allows a part of the code to be executed multiple times depending upon a given boolean condition. It can be viewed as a repeating if statement. It is an entry-controlled loop. The body of the loop will be executed as long as the condition is true. When condition becomes false, control passes to the next line of code immediately following the loop.
Syntax:
while ( Condition )
{
// body of loop ;
// Increment (or) Decrement ;
}
The program is written in C and it demonstrates the use of the while loop.
In this program, the while loop will print all the numbers from 1 to n (inclusive) that the user entered. So, the program will print 1, 2, 3 ... n numbers.
/* Looping Statement 1.Entry Check Loop While For 2.Exit Check Loop do while while(condition) { ---- ---- ---- } */ #include<stdio.h> int main() { int i=1,n; printf("\nEnter The Limit : "); scanf("%d",&n); while(i<=n) { printf("\n%d",i); i++; } return 0; }To download raw file Click Here
Enter The Limit : 10 1 2 3 4 5 6 7 8 9 10
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions