当前位置:网站首页>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
边栏推荐
- Gerapy use
- DHCP principle and configuration
- [learning notes] thread creation
- Which brand of air conduction earphones is better? These four should not be missed
- Technology sharing | interface testing value and system
- [learning notes] drive
- MySQL master master
- Insertion and deletion of nodes in linked list
- KVM热迁移
- 一、PXE概述和安装
猜你喜欢

CentOS7部署MySQL数据库服务器

Iptables firewall

SSH service configuration

Esxi community nvme driver update v1.1

Custom component -- communication between parent and child components

Installation and configuration of unit test framework jest with typescript

Network - transport layer (detailed version)

Applet custom components - data, methods, and properties

FTP service

Shell script - regular expression
随机推荐
Firewall - iptables firewall (four tables and five links, firewall configuration method, detailed explanation of matching rules)
File operation in C language
测试面试题集锦(五)| 自动化测试与性能测试篇(附答案)
What kind of air conduction Bluetooth headset with good configuration is recommended
DNS forward resolution experiment
Principle and configuration of NAT and pat
Forward and backward slash notes
cocos2d-x 学习笔记——瓦片地图TiledMap
HDU-1097-A hard puzzle(快速幂)
Esxi community network card driver
Ubuntu18.04搭建redis集群【学习笔记】
SSH服务配置
shell脚本——sort、uniq、tr、数组排序、cut、eval命令配置
DNS正向解析实验
How to calculate the size of structure, segment and Consortium (common body)
Ubuntu18.04+centos7 configure redis master-slave [learning notes]
Ubuntu MySQL setting remote access permissions
Icc2 analysis timing artifact analyze_ design_ violations
Test interview questions collection (V) | automated testing and performance testing (with answers)
Hdu-1159-commonsubsequence (LCS longest common subsequence)