The three major cycles of Java include while 、、、 does while 、、、 for
(1) Grammatical differences:
While loop
while (loop condition) { Cyclic operation (body) } |
Do and loop
bo= Cyclic operation (body) }while (cyclic conditions); |
For loop
for (initialize; loop condition; iteration) { Cyclic operation (body) } |
(2) Order of execution:
While loop: first judgment after execution
Do and loop: Judge after first execution
For loop: first judgment after execution
(3) Applicable situation:
When the number of cycles is determined, the for loop is usually used;
When the number of cycles is uncertain, the while loop or do While loop is usually selected;
Note: 1, the code indentation, to have a level, to do a good programmer;
2, the circulation can be normal exit, to avoid the death cycle;
3, the loop variable can have multiple
4, no matter which cycle, there are essential 4 parts: The initial part, the cycle condition, the loop body, the iteration part.
The first small experience of the three major cycles----Java