Java Do while repetition statement

Java Do while repetition statement: The do…while repetition statement is similar to the while statement. In the while, the program tests the loop-continuation condition at the beginning of the loop, before executing the loop’s body; if the condition is false, the body never executes. The do…while statement tests the loop-continuation condition after executing the loop’s body; therefore, the body always executes at least once.

Java Do while repetition statement

// Fig. 5.7: DoWhileTest.java
 // do...while repetition statement{CodeBlah.com}.

public class DoWhileTest
 {
 public static void main(String[] args)
 {
 int counter = 1;
do
{
System.out.printf("%d ", counter);
++counter;
} while (counter <= 10); // end do...while

System.out.println();
 }
 } // end class DoWhileTest

Output of Program

1 2 3 4 5 6 7 8 9 10