DEV Community

221910303028
221910303028

Posted on

Do While Loop:

Do while loop is used to repeat a block of statements. It is an exit control loop so, it checks the condition after executing of the statement. Do while loop consists of Test Expression and Update Expression. Since it is an exit control loop, it executes the program for at least 1 time, before execution ends.

Test Expression tests the condition and executes the statement only if the condition is satisfied.

Update Expression updates the variable loop variable by increasing or decreasing it by some value.

Example:

// initialisation expression 
int i = 1; 
do { 

    // Print the statement 
    System.out.println("Hello"); 

    // update expression 
    i++; 
} 
// test expression 
while (i < 6); 
Enter fullscreen mode Exit fullscreen mode

The above code prints Hello 5 times.

Top comments (0)