流程控制语句-------循环结构概述和for语句的格式及其使用(三)

1.循环结构的分类
   for            while             do...while
2.B:循环结构for语句的格式:
        for(初始化表达式;条件表达式;循环后的操作表达式) {
            循环体;
        }
3.执行流程:
    * a:执行初始化语句
    * b:执行判断条件语句,看其返回值是true还是false
        * 如果是true,就继续执行
        * 如果是false,就结束循环
    * c:执行循环体语句;
    * d:执行循环后的操作表达式
    * e:回到B继续。

4.在控制台输出10次"helloworld".

不使用for循环:

class Demo1_For {
	public static void main(String[] args) {
		
		System.out.println("helloworld");
		System.out.println("helloworld");
		System.out.println("helloworld");
		System.out.println("helloworld");
		System.out.println("helloworld");
		System.out.println("helloworld");
		System.out.println("helloworld");
		System.out.println("helloworld");
		System.out.println("helloworld");
		System.out.println("helloworld");
		
          //这样做不推荐,因为复用性太差

	}
}


使用for循环:

class Demo1_For {
	public static void main(String[] args) {
		
		for (int i = 1;i <= 10;i++ ) {  
	           System.out.println("helloworld");
		}
		

	}
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值