The do loop in Java is a post-test loop with conditional judgment. The loop body is executed first and then the loop condition is judged to ensure that the loop body is executed at least once.
The role of do in Java
do is a loop statement in Java; Post-test loop with conditional judgment, that is, execute the loop body first and then judge the loop condition.
Syntax:
<code class="java">do { // 循环主体 } while (条件);</code>
Function:
do loopExecute the loop body at least once, even if The condition is false. Unlike a while loop, a while loop only executes the body of the loop when the condition is true.
Usage scenarios:
do loop is usually used in the following scenarios:Process:
Example:
<code class="java">int number = 10; do { System.out.println(number); number++; } while (number <= 15);</code>
Output:
<code>10 11 12 13 14 15</code>
The above is the detailed content of The role of do in java. For more information, please follow other related articles on the PHP Chinese website!