1. Three elements of the cycle :
1) Initialization of the cyclic variables;
2) The conditions of the cycle;
3) superposition of cyclic variables;
2. syntax for the while loop:
while (Boolean expression) {
statement block;
}
Execution order:
1. Calculate the Boolean value;
2. If the Boolean value is ture, execute the statement block; after execution, in the calculation of the Boolean value, if it is ture, continue to execute the statement block, and so on, know that the Boolean value is False, the loop ends.
Example: a training institution with 250,000 people this year, an annual growth of 25%, how many years will it take to increase the number to 1 million?
public class Nian {
public static void Main (String[]args) {
Double ren=25;
int year=2012;
while (ren<=100) {
ren=ren* (1+0.25);
year++;
}SYSTEM.OUT.PRINTLN (year);
}
}
3. do and loop syntax:
do{
statement block;}while (boolean expression);
Execution order:
1. Execute the statement block first;
2. Computes the Boolean value for Ture to continue executing the statement block, and then computes the Boolean value, after executing the statement block, and so on, until the Boolean value is False, ending the loop.
Example:
public static void Main (String[]args) {
Double hua=0; int num=0;
Double she=0;
do{
if (num<10) {
SYSTEM.OUT.PRINTLN ("Celsius" +she+ "\ T" + "Fahrenheit" + (hua=she*9/5.0+32));
}
she=she+20;
num++;
}while (she<=250);
}
3. the difference between the while and do while:
Two statements are used for the execution of the loop structure, the difference is that while the loop condition is judged by the true and false, in the execution of the statement block, and does while the condition is true or FALSE, will first execute a statement block, and then in the judgment condition of the true and false, in the loop.
Cyclic--WHILE loop structure in Java