The syntax format of the while loop statement is as follows:
while(expression){//statement}
Notice:
1) The expression must be an expression that evaluates to boolean data.
2) The compound statement is called the loop body. If the loop body has only one statement, the curly brackets {} can be omitted.
Execution rules for while loop statements:
(1) Calculate the value of the expression. If the value is true, proceed to (2), otherwise proceed to (3).
(2) Execute the loop body, and then proceed to (1).
(3) End the execution of the while statement.
Example:
publicclassMain{publicstaticvoidmain(String[]args){inta=1;while(a<10){System.out.print(a);a++;System.out.print(n);}}}
The running results are as follows:
123456789