Loops allow a block of statements to be executed repeatedly (i.e., iterated). A boolean condition (called the loop condition) is commonly used to determine when to terminate the loop. The statements executed in the loop constitute the loop body. The loop body can be a single statement or a block.
Java provides three language constructs for constructing loops:
These loops differ in the order in which they execute the loop body and test the loop condition. The while and the for loops test the loop condition before executing the loop body, while the do-while loop tests the loop condition after execution of the loop body.
The syntax of the while loop is