Loop structure
Cyclic structure-while
while (condition)
{
Statement
}
Explanation: First determine whether the condition is established, the establishment of the execution, after the execution of the code again to determine whether the condition is established (judging conditions-"code block-" Judgment conditions-"execution code block ...) )
1. First determine the operation of the loop (loop in vivo statement)
2. In determining the constraints, that is, the number of cycles required (cyclic body judging conditions)
3. Define a variable to record the number of cycles (defined as needed or undefined)
Tip: use If...break (jump out of the loop) or If...continue statement in the while loop (jump out of the loop to continue the next loop).
Loop structure-do while
Do
{
Statement
}while (condition)
Features: ADo While loop performs at least one loop body
Cyclic structure-for
For (statement 1, condition, statement 2)
{
Loop body
}
Statement 1: Typically an initialization statement
Statement 2: Typically an incremental statement (a statement executed after the loop body is executed)
"Contrast" for and while:
On the performance, the for loop slightly better because the while loop can use only external variables, and for loops to recycle variables in a timely manner.
Tips: Two code implementations of the Dead loop: while (1) for (;;)
C-Language Process control structure-cyclic structure