(1) The syntax format for the For loop structure is as follows.
for (expression 1; expression 2; expression 4) {
Loop body
}
Expression 1: The initial part of the loop structure, assigning the initial value to the loop variable.
Expression 2: Loop condition of the looping structure.
Expression 3: The selected part of the looping structure, usually used to modify the value of the loop variable.
(2) Circular structure summary
different syntax:
The while loop structure statement is as follows:
while (condition) {
Loop body
}
The DO-WHILE loop structure statement is as follows:
do{
Loop body
}while (< conditions >);
The For Loop structure statement is as follows:
for (initialize; condition; select) {
Loop body
}
The execution order is different:
while loop structure: The condition is judged first, then the loop body is executed. If the condition is not true, exit the loop.
Do-while Loop structure: The loop body is executed first, then the loop is judged, and the loop body is executed at least once.
For loop structure: first executes the initialization part, then carries on the condition judgment, then executes the loop body, finally carries on the calculation of the selection part, if the condition is not established, jumps out the loop.
different application conditions:
In case of problem solving, the for loop structure is usually chosen for the number of cycles determined. For cases with uncertain cycle times, the while and do-while loop structures are usually chosen.
(3) In a loop, you can use the break and continue statements to control the flow of the program.
The break statement is used to terminate a loop, and the program jumps to the next statement outside the loop body.
The continue statement is a statement used to jump out of this loop and into the next loop.
Chapter 6th circular Structure (ii)