【for循环语句】
(概念)执行流程:
-
执行初始化语句
-
执行条件判断语句
true:继续执行
false:循环结束 -
执行循环体语句
-
执行条件控制语句
-
回到2继续
执行流程图如下:
-//需求:输出五次"hello小艺"
不用循环语句的案例:
System.out.println("hello小艺");
System.out.println("hello小艺");
System.out.println("hello小艺");
System.out.println("hello小艺");
System.out.println("hello小艺");
使用for循环语句:
for(int i = 1; i <= 5; i++) {
System.out.println("hello小艺");
}
编译运行后的结果相同,使用for循环语句很简洁。
本文详细介绍了for循环语句的执行流程,通过对比不使用循环和使用for循环输出相同结果的示例,展示了for循环语句的简洁性和实用性。
323





