当前位置:网站首页>c语言入门教程–-6循环语句
c语言入门教程–-6循环语句
2022-06-29 13:06:00 【全栈程序员站长】
c语言入门教程–-6循环语句
c语言提供了以下几种循环类型。 while循环 for 循环 do…while 循环
while循环
#include <stdio.h>
int main ()
{
/* 局部变量定义 */
int a = 10;
/* while 循环执行 */
while( a < 20 )
{
printf("a 的值: %d\n", a);
a++;
}
return 0;
}for循环
#include <stdio.h>
int main ()
{
/* for 循环执行 */
for( int a = 10; a < 20; a = a + 1 ) //for(循环前;循环条件;循环后)
{
printf("a 的值: %d\n", a);
}
return 0;
}do…while循环
#include <stdio.h>
int main ()
{
/* 局部变量定义 */
int a = 10;
/* do 循环执行,在条件被测试之前至少执行一次 */
do
{
printf("a 的值: %d\n", a);
a = a + 1;
}while( a < 20 );
return 0;
}上面是循环的3个例子,个人觉得用的最多的是第二个for,所以先弄懂for怎么写,举一反三。自己多编写一下。
循环和条件判断语句,都会编的话,绝大部分的代码都可以进行编写了。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/2899.html原文链接:https://javaforall.cn
边栏推荐
- OpenSSL certificate tool user manual
- 打造一个 API 快速开发平台,牛逼!
- Interview high concurrent, cool!! (high energy in the whole process, collection recommended)
- Openssl证书工具使用手册
- Mondo rescue creates an image file (which is conducive to image damage recovery)
- 台式机主板上保护cpu的盖子安装和拆卸
- What is the reason why the gbase8s database encountered a 951 error?
- Introduction to esp8266: three programming methods "suggestions collection"
- Distributed cache for memcached
- Wechat applet: Yunkai publishes white wall wechat applet source code download server free and domain name support traffic main revenue
猜你喜欢

现场快递柜状态采集与控制系统

【系统设计】邻近服务

Thinkpad VMware 安装虚拟机出现此主机支持 Intel VT-x,但 Intel VT-x 处于禁用状态(问题解决方法)

微信小程序:装B神器P图修改微信流量主小程序源码下载趣味恶搞图制作免服务器域名
![[document translation] camouflaged object detection](/img/30/73a927c05173a95cc5a5d51e182e3b.png)
[document translation] camouflaged object detection

Don't build the wheel again. It is recommended to use Google guava open source tool class library. It is really powerful!

Yyds dry inventory solution sword finger offer: find the nearest common ancestor of two nodes in the binary tree

Applet Wechat: un nouveau réseau exclusif de microgroupes de développement de Cloud

ANSVC无功补偿装置在河北某购物广场中的应用

打造一个 API 快速开发平台,牛逼!
随机推荐
Hardware development notes (VIII): basic process of hardware development, making a USB to RS232 module (VII): creating a basic dip component (crystal oscillator) package and associating the principle
PG Basics - logical structure management (1)
高校女生穿旗袍答辩!网友:导师说论文要是和旗袍一样漂亮就好了
Cicd introduction [easy to understand]
Discard Tkinter! Simple configuration to quickly generate cool GUI!
Weserver Publishing Map Service
php-fpm 启动参数及重要配置详解
Openssl证书工具使用手册
【系统设计】邻近服务
Cloud native (31) | kubernetes chapter kubernetes platform basic pre installed resources
[high concurrency] 28000 words' summary of callable and future interview knowledge points. After reading it, I went directly to ByteDance. Forgive me for being a little drifting (middle)
机器学习 Out-of-Fold 折外预测详解 | 使用折外预测 OOF 评估模型的泛化性能和构建集成模型
中康控股开启招股:拟募资净额3.95亿港元,预计7月12日上市
mysql函数和约束
Three best practices help enterprises improve supply chain security
Applet Wechat: un nouveau réseau exclusif de microgroupes de développement de Cloud
[cloud resident co creation] break through the performance bottleneck of image recognition through rust language computing acceleration technology
超 Nice 的表格响应式布局小技巧
weserver发布地图服务
June training (day 29) - divide and rule