day03-流程控制语句-循环流程-三种循环的区别
This commit is contained in:
38
day03/src/com/inmind/circle_diff06/Demo11.java
Normal file
38
day03/src/com/inmind/circle_diff06/Demo11.java
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user