The loop statements in C language used to repeatedly execute code blocks are: for loop: used when the number of loops is known, the syntax is for (initialization; condition; increment) {code block}. while loop: used when the number of loops is not known, the syntax is while (condition) {code block}. do-while loop: used when a code block needs to be executed at least once, the syntax is do{code block}while (condition);.
Loop statements in C language
C language provides a variety of loop statements for repeatedly executing code piece. They are:
for loop
Syntax:
<code class="c">for (初始化; 条件; 增量) { // 代码块 }</code>
Usage: When it is known that it needs to be repeated The exact number of code blocks to use.
Description:
while loop
Syntax:
<code class="c">while (条件) { // 代码块 }</code>
Usage: When you don’t know what is needed Used when repeating a code block an exact number of times.
Description:
do-while loop
Syntax:
<code class="c">do { // 代码块 } while (条件);</code>
Usage: When needed Used when a block of code is executed at least once, even if the condition is false.
Description:
The above is the detailed content of How many types of loop statements are there in C language?. For more information, please follow other related articles on the PHP Chinese website!