
package com.itheima.loop;public class WhileDemo4 {public static void main(String[] args) {// 目标:学会使用while循环,并理解他的流程int i = 0;while (i<3){ // while(条件表达式){代码...} 当条件表达式满足时,会执行下面语句System.out.println("HelloWorld"); // 输出3次i++;//不写i++会一直执行下去,因为i<3一直满足}// 死循环// while (true){// System.out.println("HelloWorld");// }// 还有一种int j =0;while (j<3){System.out.println("1111");}}}
—————————什么时候用for,什么时候用while—————————
