当前位置:网站首页>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
边栏推荐
猜你喜欢

線程組ThreadGroup使用介紹+自定義線程工廠類實現ThreadFactory接口

Storage path of mod subscribed by starbound Creative Workshop at Star boundary

TUN 设备原理

字节面试编程题:最小的K个数

统信UOS卸载php7.2.24,安装php7.4.27 ;卸载再安装为PHP 7.2.34

线程组ThreadGroup使用介绍+自定义线程工厂类实现ThreadFactory接口

squid代理

MYSQL一种分表实现方案及InnoDB、MyISAM、MRG_MYISAM等各种引擎应用场景介绍

VMware installation 64 bit XP Chinese tutorial

剑指offer刷题(1)--面向华为
随机推荐
Use cases of the arrays class
How to do a project easily
线程间控制之CountDownLatch和CyclicBarrier使用介绍
MySQL lock database lock
Returns the subscript after array sorting
dp-[NOIP2000]方格取数
JumpServer
MySQL-InnoDB-事务
Notes on Visio drawing topology
返回数组排序后下标
A table splitting implementation scheme of MySQL and InnoDB, MyISAM and MRG_ Introduction to MyISAM and other engine application scenarios
redis 模块编程中 key value的生命周期
Operation instructions of star boundary automatic text translator (advanced version)
微信小程序将原生请求通过es6的promise来进行优化
mysql 5.1升级到5.66
统信UOS PHP7.2.3升级至PHP7.2.24
VMware installation 64 bit XP Chinese tutorial
yml引用其他变量
关于UDP接收icmp端口不可达(port unreachable)
JS key value judgment