Java while loop
Java while loop
The while loop is also used to iterate over the number of statements multiple times. However, if we don't know the number of iterations in advance, it is recommended to use a while loop. Unlike for loop, the initialization and increment/decrement doesn't take place inside the loop statement in while loop.
It is also known as the entry-controlled loop since the condition is checked at the start of the loop. If the condition is true, then the loop body will be executed; otherwise, the statements after the loop will be executed.
The syntax of the while loop is given below.
The flow chart for the while loop is given in the following image.
Consider the following example.
//print "I am Indian" 10 times.
Output:
I am Indian I am Indian I am Indian I am Indian I am Indian I am Indian I am Indian I am Indian I am Indian I am Indian
Comments
Post a Comment