Current location - Recipe Complete Network - Complete cookbook of home-style dishes - Explanation of java for loop
Explanation of java for loop
Looping means having the program execute certain statements repeatedly. When programming, you often need to deal with a lot of repetitive actions. Using circular structure can reduce the length and complexity of programming, simplify complex problems and improve the readability and execution speed of programs. Among them, for loop is a kind of loop structure, as well as while loop and do-while loop statements. But the for loop is that the developer clearly knows the number of loops.

The format of the for loop is as follows:

For (allocate initial value; Judging conditions; Assignment addition and subtraction) (

execute statement

}

If there is only one statement to be processed in the loop body, you can omit the braces. The process of the for loop is as follows:

When (1) enters the for loop for the first time, it is necessary to assign an initial value to the loop control variable.

(2) Check whether to continue executing the loop according to the content of the judgment condition, and when the judgment condition is true, continue executing the statement in the loop body; When the judgment condition is false, it will jump out of the loop and execute other statements.

After executing the statement in the loop body, the loop control variable will change its value according to the requirements of increase or decrease, and then return to step (2) to judge whether to continue executing the loop. More importantly, you can draw the following flow chart on it.

The following are successful examples.