There are three basic structures of the program: 1. Sequential structure, each operation in the program is executed in sequence from top to bottom according to the order in which it is arranged in the source code; 2. Selection structure, based on a specific condition After making the judgment, select one of them to execute; 3. Loop structure, in the program, one or more operations need to be repeatedly performed until the condition is false or true, and the loop will not stop.
The operating environment of this tutorial: Windows 7 system, Dell G3 computer.
Any simple or complex algorithm can be composed of three basic structures: sequential structure, selection structure and loop structure. Let's take a look at these three basic structures.
Sequential structure
The sequential structure is the simplest program structure. Each operation in the program is based on their order in the source code. The order of arrangement is from top to bottom.
The flow chart is as follows:
Selection structure
Selection structure is used for judgment Given conditions, the flow of the program is controlled. It will select one of them for execution after judging based on a specific condition.
The flow chart is as follows:
Loop structure
The loop structure refers to A program structure that requires repeated execution of one or more operations until the condition is false or true.
It determines whether to continue executing a certain function or to exit the loop based on the conditions in the loop body. According to the judgment conditions, the loop structure can be subdivided into the following two forms:
● When type loop structure: judge (condition) first and then execute.
● Until loop structure: execute first and then judge.
The loop structure can be seen as a combination of a conditional judgment statement and a turnaround statement. In addition, there are three elements of the loop structure: loop variables, loop body and loop termination condition. The loop structure is represented by a judgment box in the program block diagram. The conditions are written in the judgment box. The two exits correspond to the condition establishment and the condition respectively. Among the different instructions executed when it is not true, one of them should point to the loop body, and then return from the loop body to the entrance of the judgment box.
The flow chart is as follows:
"When type" loop: Execute block A when the given condition is met, otherwise block A will not be executed and jump directly to the following part for execution.
"Until type" loop: Its meaning is: Execute block A until the given conditions are met (block A will no longer be executed if the conditions are met).
For more programming-related knowledge, please visit:Programming Teaching! !
The above is the detailed content of What are the three basic structures of a program?. For more information, please follow other related articles on the PHP Chinese website!