Java while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition.
Example 1
public class WhileLoop_Example1 {
public static void main(String[] args) {
int i = 1;
while (i <= 10) {
System.out.print(i);
System.out.print(" ");
i++;
}
}
}
Example 2: Multiplication Table of 3 up to 20.
public class WhileLoop_Example2 {
public static void main(String[] args) {
int i = 1, mult = 3;
while (mult < 20) {
System.out.print(mult + " ");
i++;
mult = i * 3;
}
}
}