当前位置:网站首页>MOOC翁恺 C语言 第三周:判断与循环:2.循环
MOOC翁恺 C语言 第三周:判断与循环:2.循环
2022-07-28 05:28:00 【W.934】
1.while( ){......}
先判断条件,再进循环体。
反复多次,判断条件
当条件满足时,不断重复循环体内的语句。
()条件
{ }循环体
2.do-while
do
{
<循环体语句>
}while(<循环条件>);
先进循环体,再判断条件。
3.for循环
for(表达式1;表达式2;表达式3){ 循环体 }
表达式1:初始动作(循环变量赋初值)
表达式2:循环继续的条件(条件判断语句)
表达式3:循环每一轮要做的事情(循环变量增量)
执行过程如下:
1)先求解表达式1。
2)再求解表达式2,若其值为真(非0),则执行for语句中指定的内嵌语句,然后执行下面的第3)步;若其值
为假(0),则结束循环,转到第5)步。
4)转回上面第2)步继续执行。
5)循环结束,执行for语句下面的一个语句。
就读成:“对于一开始的“表达式1”,当“表达式2”时,重复做循环体,每一轮循环在做完循环体内语句后,使得“表达式3””。
eg:
for(i=1;i<=100;i++)
{
sum=sum+i;
}先给i赋初值1,判断i是否小于等于100,若是 则执行语句,之后值增加1.再重新判断,直到条件为假,即i>100时,结束循环。
for中的每一个表达式都是可以省略的:
for(;条件;)==while(条件)

tips:
如果有固定次数,用for
如果必须执行一次,用do-while
其他情况用while
边栏推荐
- Scratch command
- 测试面试题集锦(五)| 自动化测试与性能测试篇(附答案)
- Shell script - sort, uniq, TR, array sort, cut, Eval command configuration
- 什么是线性表?
- shell脚本——sort、uniq、tr、数组排序、cut、eval命令配置
- raid磁盘阵列
- 1、 PXE overview and installation
- It is recommended to wear air conduction earphones, which do not need to wear in ear
- 测试面试题集锦(三)| 计算机网络和数据库篇(附答案)
- Vmware workstation configuration net mode
猜你喜欢

Principle and configuration of NAT and pat

VMware Workstation 配置net模式

Vmware workstation configuration net mode

iptables防火墙

shell脚本——正则表达式

Installation and configuration of unit test framework jest with typescript

技术分享 | 实战详解接口测试请求方式Get、post

MySQL master-slave

Shell script - sort, uniq, TR, array sort, cut, Eval command configuration

Archery database audit platform deployment
随机推荐
Difference between process and thread
Archery database audit platform deployment
Technology sharing | detailed explanation of actual combat interface test request methods get, post
Installation and configuration of unit test framework jest with typescript
防火墙——iptables防火墙(四表五链、防火墙配置方法、匹配规则详解)
Esxi community network card driver
Escape character notes
Hdu-1097-a hard puzzle (fast power)
Regular execution of scratch
Servlet
Which is the best one to make air conduction headphones? Inventory of the best air conduction headphones
测试面试题集锦(二)| 测试工具篇(附答案)
测试面试题集锦(五)| 自动化测试与性能测试篇(附答案)
Build php7 private warehouse
技术分享 | 如何模拟真实使用场景?mock 技术来帮你
Hdu-5806-nanoapelovesequence Ⅱ (ruler method)
Create, traverse and search nodes as required for single linked list
组管理和权限管理
Ubuntu18.04 set up redis cluster [learning notes]
shell脚本——sort、uniq、tr、数组排序、cut、eval命令配置