While syntax format:
while (Boolean expression) {
Statement
}
The Boolean expression is judged first, if true, the statement in the loop body is executed, then the Boolean expression is determined until the Boolean expression is false and the loop ends.
Usually with arithmetic operator (+ +--decrement)
Class Whiledemo{public static void Main (String [] args) {int x=1;while (x<4) {System.out.println ("OK"); x + +;}}
Do-while Syntax Format:
do{
Statement
}while (boolean expression);
Executes the loop body first, then determines whether the Boolean expression is true, and if so, resumes execution of the loop body, judging the Boolean expression until false to end the loop.
Class Dowhiledemo{public static void Main (String [] args) {int x=1;do{system.out.println ("OK Do_while"); x + +;} while (x<4);}}
The difference between the two: while is the first judgment in the execution if the judgment is not established, will not be executed; Do/while is executed first in judgment, regardless of whether the judgment is established.
"Java" talking about while and do-while