Usage of do while loop in C language: execute the loop body at least once, and then continue execution when the conditional expression is checked to be true. Terminates the loop when the conditional expression is false. Unlike a while loop, the conditional expression is executed once even if it is false.
Usage of do while loop in C language
Introduction:
The do while loop is a statement that implements a loop structure in C language. It executes the loop body at least once before executing the conditional statement.
Syntax:
<code>do { // 循环体语句 } while (条件表达式);</code>
Working principle:
Features:
Example:
<code class="c">int main() { int num = 10; do { printf("Num: %d\n", num); num--; } while (num >= 0); return 0; }</code>
Output:
<code>Num: 10 Num: 9 Num: 8 Num: 7 Num: 6 Num: 5 Num: 4 Num: 3 Num: 2 Num: 1 Num: 0</code>
Notes:
The above is the detailed content of How to use do while in c language. For more information, please follow other related articles on the PHP Chinese website!