Looping Statement in Java

In looping, a sequence of statements are executed until some conditions for the termination of the loop are satisfied. A program loop consists of two segments , One is known as the body of the loop and the other one known as control statement. Java language provides three types loop construct. They are :

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

    for (intialization;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 of 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 : The do-while statment, the program proceeds to evaluated the body of the loop first. At the end of the loop, test condition in the while statement is evaluated. If the condition is true, the program continues to evaluated 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)