当前位置:网站首页>for循环的3个表达式执行顺序
for循环的3个表达式执行顺序
2022-07-30 12:24:00 【R-G-B】
一、形式:
for(表达式1; 表达式2; 表达式3){
循环语句块
}
for(int i=1; i<10; i++){
print(“hello world”)
}
二、代码执行顺序:
1) 先执行“表达式1”,只在初始化时执行一次。
2) 再执行“表达式2”,如果它的值为真(非0),则执行循环体,否则结束循环。
3) 执行完循环体后再执行“表达式3”。
4) 重复执行步骤 2) 和 3),直到“表达式2”的值为假,就结束循环。
三 、验证
int main() {
int n;
cin >> n;
if (n <= 2) cout << n << endl;
for (int i = 3; i <= n; i++)
cout << "进入循环"<< i << endl;
}
输入1执行if (n <= 2) cout << n << endl;
输入2,执行if (n <= 2) cout << n << endl;
输入3,执行了“
边栏推荐
猜你喜欢
Go 事,Gopher 要学的数字类型,变量,常量,运算符 ,第2篇
爱可可AI前沿推介(7.30)
来n遍剑指--04. 二维数组中的查找
js 构造函数 return 非空对象,其实例化的对象在原型上的差异
ModelCoder状态机:对柴油机工况判断策略进行建模
Beijing, Shanghai and Guangzhou offline events丨The most unmissable technology gatherings at the end of the year are all gathered
Kubernetes之本地存储
概率论的学习整理--番外2:和二项式,组合相关的杨辉三角
Rust 从入门到精通02-安装
New:WebKitX ActiveX :::Crack
随机推荐
Kubernetes之本地存储
【河北工业大学】考研初试复试资料分享
OpenHarmony环境搭建报错: ImportError: cannot import name ‘VERSION‘ from ‘hb.__main__‘
Xms Xmx PermSize MaxPermSize 区别
IO/multiplexing (select/poll/epoll)
打破原则引入SQL,MongoDB到底想要干啥???
C#实现软键盘的制作
A tutorial on how to build a php environment under win
手慢无!阿里亿级流量高并发系统设计核心原理全彩笔记现实开源
[PostgreSQL] - Storage structure and cache shared_buffers
和数集团:让智慧城市更智慧,让现实生活更美好
Beijing, Shanghai and Guangzhou offline events丨The most unmissable technology gatherings at the end of the year are all gathered
我又造了个轮子:GrpcGateway
MySQL查询性能优化
PanGu-Coder: 函数级的代码生成模型
漫谈金丝雀部署(Canary Deployment)
dbaplus丛书丨《MySQL DBA工作笔记》限量签名版来了!
Dry Goods Sharing: Various Implementation Methods of Bean Management Factory with Great Use of Small Skills
Scala基础:数组(Array)、映射(Map)、元组(Tuple)、集合(List)
爱可可AI前沿推介(7.30)