Home  >  Article  >  What are the principles of structured programming?

What are the principles of structured programming?

青灯夜游
青灯夜游Original
2021-03-10 11:45:4633467browse

There are four main principles of structured programming: 1. Top-down; start designing from the top overall goal and gradually make the problem concrete. 2. Gradually seek refinement; for complex problems, some sub-goals should be designed as transitions and gradually refined. 3. Modularization. 4. Limit the use of goto statements.

What are the principles of structured programming?

The operating environment of this tutorial: Windows 7 system, Dell G3 computer.

Structured programming is the basic principle for detailed design focusing on module function and process design. Structured programming is a subset of procedural programming that uses logical structures in written programs to make understanding and modification more efficient and easier.

There are four main principles of structured programming:

1. Top-down: When designing a program, you should consider the overall situation first and then the details; consider the global goals first and then the local goals. Don't pursue too many details at the beginning. Start designing from the top overall goal and gradually make the problem concrete.

2. Gradual refinement: For complex problems, some sub-goals should be designed as transitions and gradually refined.

3. Modularization: A complex problem must be composed of several simpler problems. Modularization is to decompose the overall goal to be solved by the program into sub-goals, and then further decompose it into specific small goals, and call each small goal a module.

4. Limit the use of goto statements

The origin of structured programming methods comes from the understanding and debate on GOTO statements. The definite conclusion is: GOTO statements are often needed at abnormal exits of blocks and processes. Using GOTO statements will make program execution more efficient; GOTO statements are often useful when synthesizing program targets, such as using GOTO for return statements.

The negative conclusion is: GOTO statements are harmful and the root of program confusion. The quality of the program is inversely proportional to the number of GOTO statements. GOTO statements should be canceled in all high-level programming languages. After canceling the GOTO statement, the program is easy to understand, easy to troubleshoot, easy to maintain, and easy to prove correctness. As a conclusion to the debate, in 1974 Knuth published a convincing summary and eliminated the GOTO statement.

For more related knowledge, please visit the FAQ column!

The above is the detailed content of What are the principles of structured programming?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn