Java 中do...while()的使用
2022/1/15 17:05:44
本文主要是介绍Java 中do...while()的使用,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
do…while语句
基本格式:
do {
循环体语句
}while(条件判断语句);
完整格式:
初始化语句;
do{
循环体语句
条件控制语句
}while(条件判断语句);
执行流程:
-
执行初始化语句
-
执行循环语句
-
执行条件控制语句
-
执行条件判断语句,看其结果是true还是false
如果为true,继续执行
如果为false,循环结束 -
回到2继续执行
public class doWhileTest { public static void main(String[] args) { //需求:在控制台输出5次hello,world for (int i = 1; i <= 5; i++) { System.out.println("hello,world"); } System.out.println("---------"); int j = 1; do { System.out.println("hello,world"); j++; } while (j <= 5); } }
输出结果:
hello,world hello,world hello,world hello,world hello,world --------- hello,world hello,world hello,world hello,world hello,world
这篇关于Java 中do...while()的使用的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-21订单系统资料入门教程:轻松管理你的订单
- 2024-09-21Java部署资料:新手入门教程
- 2024-09-21Java部署资料:新手入门教程
- 2024-09-21Java订单系统资料:新手入门教程与实战指南
- 2024-09-21Java管理系统资料入门教程
- 2024-09-21从零开始学习Java监控系统资料
- 2024-09-21Java就业项目资料:新手入门的必备教程
- 2024-09-21Java全端资料:初学者指南
- 2024-09-21Java全栈资料入门教程及资源汇总
- 2024-09-21Java日志系统资料入门教程