The usage syntax of while statement in c language is such as "while(condition) {statement(s);}". The statement can be a single statement or a statement block, and its condition can be any expression. true is any non-zero value and the loop iterates when the condition is true.
The operating environment of this article: Windows 7 system, version C11, Dell G3 computer.
The while loop in C programming will execute the target statement repeatedly as long as the given condition is true.
The syntax of while loop in c language
while(condition) { statement(s); }
Here, the statement can be a single statement or a block of statements. The condition can be any expression, and true is any non-zero value. The loop iterates when the condition is true.
When the condition is false, program control is passed to the line immediately following the loop.
Flowchart
The key point to note here is that the while loop may not execute at all. When the condition test result is false, the loop body will be skipped and the first statement after the while loop will be executed.
Usage example:
#includeint main () { int a = 10; while( a < 20 ) { printf("value of a: %d\n", a); a++; } return 0;}
Output:
value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 value of a: 16 value of a: 17 value of a: 18 value of a: 19
Recommended related C language video tutorial: "C Tutorial》
The above is the detailed content of Usage of while statement in c language. For more information, please follow other related articles on the PHP Chinese website!