Java do-while loop
Java do-while loop
The do-while loop checks the condition at the end of the loop after executing the loop statements. When the number of iteration is not known and we have to execute the loop at least once, we can use do-while loop.
It is also known as the exit-controlled loop since the condition is not checked in advance. The syntax of the do-while loop is given below.
The flow chart of the do-while loop is given in the following image.
Consider the following example to understand the functioning of the do-while loop in Java.
- //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
- //print 1 to 100.
Output:
1 2 3 4 5 6 7 8 9 10
Comments
Post a Comment