The while of the Java Loop statement
In life, there are times when you need to repeat certain actions in order to accomplish a task. If you participate in a 10000-metre long distance running, you need to run 25 laps around the 400-metre track repeatedly. When implementing functionality in Java, it is often necessary to execute some code repeatedly, for example, in order to express "strong love", we want to output 1000 lines "I adore class net!" ”。 Obviously, at this time repeatedly knocked 1000 times output statement is not reliable drop!! So, there is a good way to solve the wood? There, looping statements !
3 types of loops commonly used in Java: While , Do...while, for
We're going to talk about while in this section.
Syntax: 650) this.width=650; "src=" http://img.mukewang.com/53699fb9000143d801590067.jpg "/>
Execution process:
< 1 >, determine if the condition behind the while is established (True/false)
< 2 >, when the condition is established, execute the operation code within the loop, then repeat < 1 >, < 2, until the loop condition is not established
Features: first judgment, after execution
Such as:
650) this.width=650; "src=" http://img.mukewang.com/5369a5910001ccb503750113.jpg "/>
Code:
public class HelloWorld {
public static void Main (string[] args) {
int i = 1; Represents a number between 1-5
Loop is executed when the variable is less than 5 o'clock
while (i<=5) {
The value of the output variable, and add 1 to the variable for the next loop condition to be judged
System.out.println (i);
i++;
}
}
}
Operation Result:
1
2
3
4
5
This article is from "Ghost" blog, please make sure to keep this source http://caizi.blog.51cto.com/5234706/1547738
Java Basics---The while (22) of the Java Loop statement