The syntax format of the do-while loop statement is as follows:
do{//statement}while(expression)
Notice:
The difference between a do-while loop and a while loop is that the body of the do-while loop is executed at least once.
Execution rules for do-while loop statements:
(1) Execute the loop body, and then proceed to (2).
(2) Calculate the value of the expression. If the value is true, proceed to (1), otherwise proceed to (3).
(3) End the execution of the do-while statement.
Example:
publicclassMain{publicstaticvoidmain(String[]args){inta=1;do{System.out.print(a);a++;System.out.print(n);}while(a<10);}}
The running results are as follows:
123456789