Loop Structure program design, structure Program Design
The main contents include:
For Loop Structure
For statement format:
For (initialization expression; conditional expression; Incremental expression)
Loop body statement Block
Where:
1. Initialization expression: It is generally a value assignment expression, which is usually used to assign an initial value to the cyclic variable. Loop variables control whether or not the loop is executed. If an initial value is assigned to the loop variable outside the for statement, this expression can be omitted.
2. conditional expression: it is usually a cyclic condition, usually a relational expression or a logical expression.
3. incremental expression: it is usually used to modify the value of the cyclic variable, which is generally a value assignment statement. Controls the direction in which the variable changes after each loop.
The for statement execution process is:
(1) calculate the value of the initialization expression.
(2) calculate the value of the conditional expression. If the value is true (not 0), execute the statement in the loop body and convert it to (3). If the value is false (0), convert it to (4 ).
(3) calculate the value of the incremental expression and convert it to (2) Repeated execution.
(4). End the loop.