Public class test02 {
Public void test01 () {
//while loop statement: judgment before execution
Int input=5;
While (input & lt; 5) {
System. The out. Println (input);
Input + +;
}
}
Public void test02 () {
//do... While loop statement: perform a first, judge,
Int input=5;
Do {
System. The out. Println (input);
} while (input & lt; 5);//while don't need a {...
} statement body
}
Public static void main (String [] args) {
Test02 test=new test02 ();
Test. Test01 ();
Test. Test02 ();
}
}
CodePudding user response:
Is bai successively judgment problem,Look at the writing
Du type while (expression) statement
Do {statement}
While (expression);
The circulation and the while loop is different: it execute dao in the loop statement first, and then determine whether the expression is true, if is true then continue to cycle; If false, the termination of circulation, therefore, the do - to perform at least once a while loop loop statement,
Use the following points should be paid attention to while statement:
1, while statement or logical expression is generally relationship expression in expression, as long as the value of the expression is true (non-zero) can continue to cycle,
2, the loop body consists of more than one statement, it must be enclosed in {}, form a compound statement,