Looping Statement in Java

In looping, a sequence of statements is executed until some conditions for the termination of the loop are satisfied. The looping Statement in Java consists of two segments, One is known as the body of the loop and the other one is known as the control statement. There are three types of Looping statements in Java. They are:

  • for loop
  • while loop
  • do-while

1. for loop: The for loop is an entry-controlled loop that provides a more concise loop control structure. The syntax of for loop :


for (initialization;test condition;increment)
{
Body of the loop
}

2. while loop: It is also an entry-controlled loop statement. The test condition is evaluated and if the condition is true then the body of the loop is executed. After the body, the test condition is once again evaluated and if it is true, the body is executed once again. This process of repeated execution of the body continues until the test condition finally becomes false and the control is transferred out of the loop. The syntax of for loop:

Initialization:
while(test condition)
{
Body of the loop
}

3. do-while loop: In the do-while statement, the program proceeds to evaluate the body of the loop first. At the end of the loop, the test condition in the while statement is evaluated. If the condition is true, the program continues to evaluate the body of the loop once again. This process continues as long as the condition is true. When the condition becomes false, the loop will be terminated.

Initialization:
do
{
Body of the loop
}
while(test condition)