[rps-include post=6557]
[rps-include post = 6557]
For loop is generally used for specified arrays or similar array like lists. For enumerates over given way and checks the condition whether it is met or not. Here is For syntax.
For循环通常用于指定的数组或类似列表的数组。 用于以给定方式枚举并检查条件是否满足。 这是For语法。
for (initialize;condition;increment)
{
statements
}
Initialize
fired one time at the start of for loop and generally used to set some values. Condition is checked in every turn of loop and if condition is met for loop is ended. Increment is run is every turn of loop and generally used to change condition related value. Now the best way to understand is doing it.
Initialize
在for循环开始时触发一次,通常用于设置一些值。 条件是在循环动辄检查,如果条件得到满足的循环结束。 增量运行是每转一圈,通常用于更改条件相关的值。 现在最好的理解方法就是这样做。
#include <stdio.h>
int main() {
for(int a=1;a<10;a++)
{
printf("%d\n",a);
}
return 0;
}
This example is similar to the previous while example.
此示例与之前的while示例相似。
int a=1; is initializer and defines new variable named a and set its value as 1.
int a = 1; 是初始值设定项,并定义名为a的新变量,并将其值设置为1。
a++ runs in every loop and increments a value like 2,3,4,5,..,9
a ++在每个循环中运行,并递增一个值,例如2,3,4,5,..,9
a<10; is checked in every loop if a is lower then 10 if the condition is not met which is where a is 10 the for loop ends.
a <10; 在每个循环中检查a是否小于10,如果不满足条件( a为10的条件),则for循环结束。
{ printf(“%d\n”,a); } will print a value in every loop.
{printf(“%d \ n”,a); }将在每个循环中打印一个值。
无限循环 (Infinite For Loop)
There are different ways to implement infinite For loop like below.
有多种实现无限For循环的方法,如下所示。
for(;;)
{
printf("Infinite loop");
}
OR
要么
for(;1=2;)
{
printf("Infinite loop");
}
OR
要么
for(;true;)
{
printf("Infinite loop");
}
[rps-include post=6557]
[rps-include post = 6557]