我的代码人生,循环之whil循环

while循环是循环中比较简单的一种循环。能简单的规定循环次数。
举例:把“hello word”打印5次

System.out.print("hello word");
System.out.print("hello word");
System.out.print("hello word");
System.out.print("hello word");
System.out.print("hello word")

这样打印五次很简单可是要是打印10次,100次呢,写一百次打印语句吗?当然不可以,这时候用while就可以很容易的做到。while(条件:循环100次)就可以了。

int i=0;
		while(i<100) {
			System.out.println("hello,word");
			i++;
		}

定义一个变量i为0,while(i<100)的意思是只要i<100就循环一次在循环中加入i++在每一次循环中i都比之前多1,这样在i等于100时i就不小于100循环终止就可以了。
本篇博客仅是个人观点,仅供新手参考学习。如有不对望指出本人及时更改。

你可能感兴趣的:(代码人生)