Do While loop

A do-while loop is used to repeatedly execute a set of statements until the condition that it uses evaluates to false.

This loop checks the condition after it completes the execution of all the statements in its loop body.

Example 1: Program to print line 10 times

package com.test.test1;

public class DoWhileEx {
	public static void main(String[] args) {
		int x = 1;
		do {
			System.out.println("Line : "+x);
			x++;
		} while (x <= 10);
	}

}
Line : 1
Line : 2
Line : 3
Line : 4
Line : 5
Line : 6
Line : 7
Line : 8
Line : 9
Line : 10

While Vs Do-while loop :

Problems:

Try all the examples as well as problems with while loop which are mentioned in for loop section.

Last updated