A break statement can exit the while-loop statement.
public class Main { public static void main(String[] args) { int i = 1;/*from w ww . j a va 2 s. co m*/ while (true) { // Cannot exit the loop from here if (i <= 10) { System.out.println(i); i++; } else { break; // Exit the loop } } } }