C For循环和迭代

[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 value like 2,3,4,5,..,9

    a ++在每个循环中运行,并递增一个值,例如2,3,4,5,..,9

  • a<10; is checked in every loop if is lower then 10 if the condition is not met which is where is 10 the for loop ends.

    a <10; 在每个循环中检查a是否小于10,如果不满足条件( a为10的条件),则for循环结束。

  • {  printf(“%d\n”,a); } will print 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]

LEARN MORE  How To Loop and Iterate Over Python Dictionary?
了解更多信息如何循环和遍历Python字典?

翻译自: https://www.poftut.com/c-loop-iteration/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值