What is the syntax and execution order of the while loop structure
Syntax: while(judgment condition){execute statement}, first determine whether the judgment condition is satisfied, if satisfied then execute the statement inside the curly braces, if not satisfied then the loop ends. For example:
int
i=1;
while(i<3){i++;}
first i=1
So i<3, enter into the loop, will be i +1; after the end of the i=2, then i<3 to continue to execute +1; after the end of the i=3, does not satisfy the conditions of the loop, end.
I. Loop structure
Loop structure can reduce the source program to repeat the workload of writing, used to describe the repetition of the execution of a particular section of the algorithm, which is the program design of the most computer expertise in the program structure
. A loop structure can be thought of as a combination of a conditional judgment statement and a turn-back statement.
II. Introduction to the structure
The loop structure can be seen as a combination of a conditional judgment statement and a turn-back statement. In addition, the three elements of a loop structure:loop variable, loop body and loop termination condition.
The loop structure is represented in the block diagram by the use of a judgment box, in which a condition is written, and two exits corresponding to different instructions that are executed when the condition is valid and when it is not, one of which should point to the loop body, and then from the loop body back to the entry point of the judgment box.
Third, the loop structure
When the condition is valid, the code of the loop body is executed, when the condition is not valid, the loop is jumped out of the loop, and the code behind the loop structure is executed.
Loop structure can reduce the source program to repeat the workload of writing, used to describe the problem of repeated execution of a particular algorithm, which is the program design of the program structure of the best use of the computer’s strengths
. The loop structure can be seen as a combination of a conditional judgment statement and a turn-back statement. In addition, there are three elements of a loop structure:the loop variable, the loop body, and the loop termination condition. The loop structure is represented in the program block diagram using a judgment box in which the condition is written, two exits corresponding to different instructions executed when the condition holds and when the condition does not hold, one of which is to point to the loop body, and then from the loop body back to the entry point of the judgment box.
Four, two common loop structure
1. When the type of loop: the first to determine whether the given condition p is valid, if p is valid, then the implementation of A (step); and then determine whether the condition p is valid; if p is valid, then the implementation of A, if this is repeated until a time when the condition p does not hold.
2. Until the type of loop: the first execution of A, and then determine whether the given condition p is established, if p is not established, then execute A, and so on, until p is established, the end of the cycle process.