From http://www.cnblogs.com/ggjucheng/archive/2012/12/16/2820841.html
English from http://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html
The while statement continuously executes the statement in the block when the specific condition is true. Its statement can be expressed as follows:
While (expression) {Statement (s )}
A boolean value must be returned for the expression calculated by the while statement. If the expression is calculated as true, the while statement executes all the statements in the while block. The while statement continues to test the expression, and then executes its blocks until the expression is calculated as false. Use the while statement to print the values from 1 to 10, as shown in figureWhiledemoProgram:
Class whiledemo {public static void main (string [] ARGs) {int COUNT = 1; while (count <11) {system. out. println ("count is:" + count); count ++ ;}}}
Use the while statement to implement an infinite loop:
While (true) {// your code goes here}
JavaProgramming LanguageThe do-while statement is also supported. The statement is as follows:
Do {Statement (s)} while (expression );
The difference between the do-while statement and the while statement is that the expression calculated by do-while is at the bottom of the loop rather than the top. Therefore, the do block statement will be executed at least once, as shown in figureThe dowhiledemo program is as follows:
Class dowhiledemo {public static void main (string [] ARGs) {int COUNT = 1; do {system. out. println ("count is:" + count); count ++;} while (count <11 );}}