While Loop Statement
A while loop is a pre-tested loop that means controller checks the condition first and then enters in the body of while loop to execute the statements of the body. The while loop is used to execute the same block of code again and again, and repetition occurs when the block of code is finished. The execution of same block will continue until the condition is evaluated to false.
Here, the format of the while-loop is given:
{
//body of while loop
}
Flowchart of while loop
A while loop must have an update statement such as increment/decrement. So that, the controller can check the same condition for the execution of next loop after the end of current loop.
Here is a suitable example of while loop that's will help you to understand it.
loop: 1
loop: 2
loop: 3
loop: 4
loop: 5
Let's see the another example of while loop.
Program to print table.
Enter a positive integer: 10
10x1 = 10
10x2 = 20
10x3 = 30
10x4 = 40
10x5 = 50
10x6 = 60
10x7 = 70
10x8 = 80
10x9 = 90
10x10 = 100