While loop statements are simpler to use than for statements, and are simple in format;
while (judging condition) {
Circulation body
}
public class Whiletest {public
static void Main (string[] args) {
int i=1;
while (i<=10) {
System.out.println ("Hello" +i);
i++
}}
}
Effect:
Hello 1, Hello
2,
3 Hello
4
Hello 5 Hello 6 Hello 7 Hello 8 Hello 9 Hello 10
Can be used in this way;
while (true) {
Circulation body
}
The advantage of this is that it keeps looping and does not stop.
public class Whiletest {public
static void Main (string[] args) {
int i=1;
while (true) {
System.out.println ("Hello");}}
Effect:
Hello, hello, hello, hello, hello ...
There is also a doing while with a while, and the difference between the while and the while is the format of the Do while;
do{
Circulation body
}whil (Judgment statement);
The Do while executes the loop-body statement and then evaluates the statement, which means that the loop body statement executes at least once, regardless of whether or not the judgment is true.
public class Whiletest {public
static void Main (string[] args) {
int i=1;
do {
i++;
System.out.println (i);
} while (i<1);
}
}
Effect:
2