当前位置:网站首页>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)

openstack理论知识

API Gateway/API 网关(四) - Kong的使用 - 集成Jwt和熔断插件

MySQL数据库讲解(八)

Tongxin UOS php7 2.3 upgrade to php7.0 two point two four

redis数据库讲解二(redis高可用、持久化、性能管理)

x509证书cer格式转pem格式

统信UOS PHP7.2.3升级至PHP7.2.24

ThreadGroup ThreadGroup implémente l'interface threadfactory en utilisant la classe Introduction + Custom thread Factory

Storage path of mod subscribed by starbound Creative Workshop at Star boundary
随机推荐
JS parabola motion packaging method
线程间控制之CountDownLatch和CyclicBarrier使用介绍
剑指offer刷题(2)--面向华为
tcp_diag 内核相关实现 1 调用层次
Visio画拓扑图随记
统信UOS卸载php7.2.24,安装php7.4.27 ;卸载再安装为PHP 7.2.34
Thread group ThreadGroup uses introduction + custom thread factory class to implement threadfactory interface
MySQL数据库讲解(十)
微信小程序轮播图swiper
redis 模块编程中 key value的生命周期
API Gateway/API 网关(二) - Kong的使用 - 负载均衡Loadbalance
js 进度条,显示加载进度
Flop effect
MySQL-InnoDB-事务
json date时间日期格式化
Operation instructions of star boundary automatic text translator (advanced version)
JS recursion (1)
dp-[NOIP2000]方格取数
mysql 5.1升级到5.611
mysql 5.1升级到5.610