For loop syntax format:
for (initialize; Boolean expression; update) {
Statement
}
(empty; empty; empty) {
Statement
}
Express conditions directly, directly execute the loop body, will be infinite loop)
Process:
1: Initialization is performed first and only once (declaring and initializing any loop control variable) (This can leave blank, but semicolon is required)
2: Computes the Boolean expression, if I true, the loop body will be executed, if it is false the loop body will not execute, the control flow will jump to the next statement outside the For loop body
3: After the For loop body is executed, it jumps to the UPDATE statement (this statement allows us to update any loop control variable) (here we can leave blank, but required semicolon is required)
4: The Boolean expression is judged again, if true, the loop body executes, then updates again, and then judges until the end of the false,for loop
Caveats: Variable scope: Want to have scope outside the For loop, then declare it outside the loop
Friendship Association:
About the choice of for, while, Do/while: the number of known cycles is used for, unknown sequential times with while and do/while (if it is to be executed before judging by Do/while)
Brief analysis of the For loop in Java