diff --git a/day03/src/com/inmind/circle_diff06/Demo11.java b/day03/src/com/inmind/circle_diff06/Demo11.java new file mode 100644 index 0000000..4ab88a6 --- /dev/null +++ b/day03/src/com/inmind/circle_diff06/Demo11.java @@ -0,0 +1,38 @@ +package com.inmind.circle_diff06; +/* +三种循环的区别: +使用场景: + for:数组的遍历,集合的遍历,字符串的遍历 ,流数据 + while:io流 + do-while:当循环体必须执行一次的时候 + +不同之处: + 当循环变量,直接不符合循环条件时,do-while一定会执行一次循环体 + for循环的循环变量,超出for的范围不能使用,就像没定义过一样 +*/ +public class Demo11 { + public static void main(String[] args) { + System.out.println("-------------for---------------"); + for (int j = 100; j <= 10; j++) { + System.out.println(j); + } + int j = 10; + + System.out.println(j); + System.out.println("-------------while---------------"); + int i = 100; + while(i<=10){ + System.out.println(i); + i++; + } + System.out.println(i); + System.out.println("-------------do-while---------------"); + //1~10 + int k = 100; + do{ + System.out.println(k); + k++; + }while(k <=10); + System.out.println(k); + } +}