C语言中的多种形式的循环结构

C语言提供了多种循环结构,包括for循环、while循环、do-while循环和foreach循环等。

复制代码
//for循环
for (int i = 0; i < 10; i++) {  
    printf("%d\n", i);  
}

//while循环
int i = 0;  
while (i < 10) {  
    printf("%d\n", i);  
    i++;  
}

//do-while循环
int i = 0;  
while (i < 10) {  
    printf("%d\n", i);  
    i++;  
}

//foreach循环(在C语言中通常使用基于迭代的循环结构)
int arr[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};  
for (int i = 0; i < sizeof(arr) / sizeof(int); i++) {  
    printf("%d\n", arr[i]);  
}
相关推荐
Navigator_Z20 小时前
LeetCode //C - 1319. Number of Operations to Make Network Connected
c语言·算法·leetcode
fengkai454520 小时前
Python运维实战
运维·开发语言·python·ssh·sftp·paramiko
Zwawa21 小时前
步进电机路径规划:梯形曲线与S型曲线
c语言·单片机·嵌入式
ShineWinsu1 天前
对于Qt:重写事件步骤的解析
开发语言·c++·qt·客户端·事件·鼠标事件·步骤
2501_930707781 天前
使用C#从 PowerPoint 演示文稿中提取图片
开发语言·c#·powerpoint
zhanghaha13141 天前
C# 系列教程_15 类 Class 保姆级系统教程(面向新手,大量示例 + 底层机理)
java·开发语言·c#
Navigator_Z2 天前
LeetCode //C - 1318. Minimum Flips to Make a OR b Equal to c
c语言·算法·leetcode
yiangL_2 天前
课后作业4:基于 Python 的古诗词词云可视化(P205)
开发语言·python
geovindu2 天前
rust: Functional Options Pattern
开发语言·后端·设计模式·rust·函数式选项模式·惯用法型模式
skywalk81632 天前
把「假成功」赶出工具层:lightharness 两天升级复盘(4×5 模式矩阵 + 工具层 5 个缺陷)
开发语言·前端·人工智能·lightharness