package controlflowmethod;
what is while?
In Java, the while loop is used to execute a block of code repeatedly as long as a given condition is true.
public class While {
public static void main(String[] args) {
task 1
int i=0; while(i<5) { System.out.println("1"); //ANS = 1 1 1 1 i=i+1; }
task 2
int i=5; while(i>=1) { System.out.println(i); // ANS = 5 4 3 2 1 i=i-1;
}
task 3
int i=1; while(i<=10) { System.out.println(i); // ANS = 1 3 5 7 9 i=i+2; }
task 4
int i=0; while(i<10) { System.out.println(i); // ANS = 0 2 4 6 8 i=i+2;
} }
}
The above is the detailed content of control flow statemet:. For more information, please follow other related articles on the PHP Chinese website!