While loop is used to repeatedly execute a block of code while a conditional expression is true. Syntax: while (condition) { // Loop body}. It continues executing the code contained within the loop body until the condition is false.
Usage of while loop in C language
while Loop is a kind of A control structure in C that is used to repeatedly execute a block of code so that the loop continues executing while its conditional expression is true.
Syntax:
<code class="c">while (condition) { // 要重复执行的代码 }</code>
Usage:
##Conditional expression:
Loop body:
Example:
The following code uses a while loop to print numbers from 1 to 10:<code class="c">int main() { int i = 1; while (i <= 10) { printf("%d ", i); i++; } return 0; }</code>
Note:
The above is the detailed content of How to use while in c language. For more information, please follow other related articles on the PHP Chinese website!