In life, there are times when we need to repeat certain actions in order to accomplish a certain task. For example, we take a 10000-metre long run and need to go 25 laps around a 400-metre track. When implementing this functionality in Java, it is often necessary to repeatedly execute some code, for example, in order to express "determined determination", we want to output 1000 lines "I want to learn java! ”。 Obviously, let us repeatedly knock out 1000 times the output statement is not reliable!!! Then, we'll use our loop statement at this point.
3 types of loops commonly used in Java: While, Do...while, for
First, let's take a look at while
Grammar:
<1>: First of all, let's determine if the condition after the while is true (True/false)
<2> If the condition is true, the loop operation is performed
<3> then repeat <1>, <2> until the loop condition is not established.
Features: first judgment, after execution.
The while of the Java Loop statement