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.