1.while语句
while 循环会在指定条件为真时循环执行代码块,其作用与先前讲述的for语句的作用很相似,在今天的内容也会提及前面所讲的break语句跳出循环的用法。
1.2代码演示
package basic;
/**
* This is the ninth code. Names and comments should follow my style strictly.
*
* @author WU JUN 2298320301@qq.com.
*/
public class Day9 {
/**
*********************
* The entrance of the program.
*
* @param args
* Not used now.
*********************
*/
public static void main(String args[]) {
whileStatementTest();
}// Of main
/**
*********************
* The sum not exceeding a given value.
*********************
*/
public static void whileStatementTest() {
int tempMax = 100;
int tempValue = 0;
int tempSum = 0;
// Approach 1.
while (tempSum <= tempMax) {
tempValue++;
tempSum += tempValue;
System.out.println("tempValue = " + tempValue + ", tempSum = " + tempSum);
} // Of whi