Loops can execute a block of code as long as a specified condition is reached.
Loops are handy because they save time, reduce errors, and they make code more readable.
The while loop loops through a block of code as long as a specified condition is true:
public static int no = 10;
public static int num = 3;
public static int No = 15;
public static int a = 22;
public static void main(String[] args) {
// ******************10 8 6 4 2******************
while (no >= 1) {
System.out.print(no + " ");
no = no - 2;
}
// ******************3 6 9 12 15******************
System.out.println();
while (num <= 15) {
System.out.print(num + " ");
num = num + 3;
}
System.out.println();
// ******************15 12 9 6 3******************
while (No >= 3) {
System.out.print(No + " ");
No = No - 3;
}
}