当前位置:网站首页>1分钟看懂执行流程,永久掌握for循环(附for循环案例)
1分钟看懂执行流程,永久掌握for循环(附for循环案例)
2022-04-23 14:12:00 【Zinksl】
:::info
根据 遗忘曲线:如果没有记录和回顾,6天后便会忘记75%的内容
读书笔记正是帮助你记录和回顾的工具,不必拘泥于形式,其核心是:记录、翻看、思考
:::
使用循环的条件:
某个操作需要重复执行多次
1 for循环
for循环使用格式
for循环的使用格式:
在for循环中,初始化语句只执行1次;
for循环案例1 连续输出三段内容
//for循环格式:
for(初始化语句;条件判断语句;条件控制语句){
//循环体语句;
}
//for循环案例:
public static void main(String[] args) {
for(int i =0;i<3;i++){
System.out.println("执行第"+i+"次循环!");
}
}
for循环执行流程(重中之重)
执行流程解析,语句模块划分,图解
for(初始化语句;条件判断语句;条件控制语句){
//循环体语句;
}
- for循环案例2(干饭倒计时案例)
//for循环案例2(干饭倒计时)
for (int i=10;i>=0;i--){
if (i !=0 ){
System.out.println("干饭倒计时还有"+i+"秒");
}else {
System.out.println("干饭时间到开始干饭!");
}
}
- for循环案例3(1-100偶数和)
//for循环案例3(1-100之间的偶数和)
//实现方案1
int sum =0;
for (int i = 1;i<=100;i++){
if (i%2==0){
sum += i;
}
}
System.out.println("1-100之间偶数和为:"+sum);
//实现方案2
int sum =0;
for (int i = 2;i<=100;i+=2){
sum += i;
}
System.out.println("1-100之间偶数和为:"+sum);
版权声明
本文为[Zinksl]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Zinkse/article/details/123892733
边栏推荐
- API Gateway/API 网关(三) - Kong的使用 - 限流rate limiting(redis)
- How does void * exist?
- source insight via samba
- KVM learning resources
- squid代理
- void*是怎样的存在?
- JDBC details
- xx项目架构随记
- flannel 原理 之 TUN模式
- Some experience of using dialogfragment and anti stepping pit experience (getactivity and getdialog are empty, cancelable is invalid, etc.)
猜你喜欢
After entering the new company, the operation and maintenance engineer can understand the deployment of the system from the following items
字节面试编程题:最小的K个数
xx项目架构随记
在Clion中给主函数传入外部参数
OpenStack命令操作
VMware installation 64 bit XP Chinese tutorial
Operation instructions of star boundary automatic text translator (advanced version)
Tongxin UOS php7 2.3 upgrade to php7.0 two point two four
KVM learning resources
x509证书cer格式转pem格式
随机推荐
sar命令详解
Docker (V) MySQL installation
How does void * exist?
Mysql的安装过程(已经安装成功的步骤说明)
OpenStack命令操作
js 递归(1)
文字组合,不重复,做搜索或查询关键字匹配
Redis源码分析之HSET流程与ziplist
TLS/SSL 协议详解 (30) SSL中的RSA、DHE、ECDHE、ECDH流程与区别
预览CSV文件
Five ways of using synchronized to remove clouds and fog are introduced
错误:无法远程查找到密钥 “428F7ECC7117F726“
redis 模块编程中 key value的生命周期
修改Firebase Emulators的默认侦听IP
redis数据库讲解二(redis高可用、持久化、性能管理)
统信UOS PHP7.2.3升级至PHP7.2.24
redis数据库讲解(三)redis数据类型
redis数据库讲解(四)主从复制、哨兵、Cluster群集
Processing MKDIR: unable to create directory 'AAA': read only file system
TLS/SSL 协议详解 (28) TLS 1.0、TLS 1.1、TLS 1.2之间的区别