# 结构化编程

**结构化编程**是一种编程范式，程序由一小组单入口、单出口的控制构造搭建而成，主要是顺序、选择和迭代，而不是像goto语句那样的任意跳转。其目标是使程序文本本身就能清晰地呈现出控制流，从而提高清晰度、质量并缩短开发时间。<sup>[1](https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_and_Computation_Fundamentals/Programming_Fundamentals_%28Busbee_and_Braunschweig%29/04%3A_Conditions/4.01%3A_Structured_Programming)</sup><sup> • </sup><sup>[2](https://www.cs.odu.edu/~zeil/cs355/s25/Public/controlFlow/controlFlow__slides.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 核心主张 | 任何可计算函数都仅用三种控制结构即可表达：顺序、选择和迭代（结构化编程定理，出自伯姆与雅科皮尼，1966年）<sup>[3](https://cir.nii.ac.jp/crid/1363107371315537152)</sup><sup> • </sup><sup>[4](https://www.sciencedirect.com/topics/computer-science/structured-programming)</sup> |
| 定义性特征 | 若程序的控制流能从文本的句法结构中清晰看出，或者等价地说，若程序由一组受限制的单入口、单出口构造构成，则该程序是结构化的<sup>[2](https://www.cs.odu.edu/~zeil/cs355/s25/Public/controlFlow/controlFlow__slides.html)</sup> |
| 开创性争论 | 艾兹格·W·迪杰斯特拉的信《goto语句被认为有害》，《美国计算机学会通讯》11(3)，1968年3月，第147–148页<sup>[5](https://research.tue.nl/en/publications/go-to-statement-considered-harmful-letter-to-the-editor)</sup> |
| 反方观点 | 唐纳德·E·克努特，《使用goto语句的结构化编程》，《美国计算机学会计算综述》6(4)：261–301，1974年12月<sup>[6](https://dblp.dagstuhl.de/pid/k/DonaldEKnuth.html)</sup> |
| 实践规则 | 美国国家航空航天局的编码指南指示开发者使用尽可能简单的流控制构造，避免“goto”和setjump/longjump<sup>[7](https://swehb.nasa.gov/spaces/SWEHBVD/pages/102695794/9.03%2BCoding%2BStandards)</sup> |
| 采纳情况 | 到20世纪末，几乎所有计算机科学家都已确信，学习和应用结构化编程的概念是有益的<sup>[1](https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_and_Computation_Fundamentals/Programming_Fundamentals_%28Busbee_and_Braunschweig%29/04%3A_Conditions/4.01%3A_Structured_Programming)</sup> |

## 三种控制结构

结构化程序由三类控制结构组成，每一种高级语言都提供全部三类。<sup>[1](https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_and_Computation_Fundamentals/Programming_Fundamentals_%28Busbee_and_Braunschweig%29/04%3A_Conditions/4.01%3A_Structured_Programming)</sup>

- **顺序**按列出的次序逐条执行语句；大多数代码行都采取这种形式。<sup>[1](https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_and_Computation_Fundamentals/Programming_Fundamentals_%28Busbee_and_Braunschweig%29/04%3A_Conditions/4.01%3A_Structured_Programming)</sup>
- **选择**根据条件在两条或多条流程之间做出选择，由if-then-else和switch/case等构造实现。<sup>[1](https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_and_Computation_Fundamentals/Programming_Fundamentals_%28Busbee_and_Braunschweig%29/04%3A_Conditions/4.01%3A_Structured_Programming)</sup><sup> • </sup><sup>[8](https://www.cs.utexas.edu/~djimenez/utsa/cs2073-2/lecture6.html)</sup>
- **迭代**在条件成立时或直到条件成立之前重复一条或多条语句，由while、do-while和for循环实现。<sup>[1](https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_and_Computation_Fundamentals/Programming_Fundamentals_%28Busbee_and_Braunschweig%29/04%3A_Conditions/4.01%3A_Structured_Programming)</sup><sup> • </sup><sup>[9](https://www.ibm.com/docs/en/ztpf/1.1.2025?topic=introduction-overview-structured-forms)</sup>

第四类——分支——是让执行跳转到程序另一部分的不受控结构；这正是结构化编程所排除的类别。<sup>[1](https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_and_Computation_Fundamentals/Programming_Fundamentals_%28Busbee_and_Braunschweig%29/04%3A_Conditions/4.01%3A_Structured_Programming)</sup>每个结构化构造都有一个入口点和一个出口点，因此程序员可以用改进版本替换某个构造，而不会影响其他构造或引入错误。<sup>[10](https://intro2c.sdds.ca/B-Computations/logic)</sup>结构化程序可以从头读到尾，无需在点与点之间任意跳转。<sup>[11](https://users.csc.calpoly.edu/~jdalbey/103/Lectures/StructuredProgramming/)</sup>

## 理论基础

其数学基础是通常被称为结构化编程定理的成果。[科拉多·伯姆](https://www.edgepedia.org/zh/corrado-bohm)和朱塞佩·雅科皮尼当时均任职于罗马的国际计算中心与国立计算应用研究所，他们于1966年5月在《美国计算机学会通讯》9(5)第366–371页发表了《仅含两条构成规则的流程图、图灵机与语言》。<sup>[3](https://cir.nii.ac.jp/crid/1363107371315537152)</sup>该论文表明，每一张流程图都可以规范化为一小组基本图的复合：一种规范化方法使用三张基本图，第二种仅使用两张，该结果被用来证明每台[图灵机](https://www.edgepedia.org/zh/turing-machine)都可归约为一个构成规则为复合与迭代的程序。<sup>[12](https://www.cs.unibo.it/~martini/PP/bohm-jac.pdf)</sup>按照编程实践所采纳的形式，该定理表述为：顺序、选择和迭代这三种构造足以表达任何编程逻辑。<sup>[4](https://www.sciencedirect.com/topics/computer-science/structured-programming)</sup><sup> • </sup><sup>[13](https://www.msuniv.ac.in/images/distance%20education/learning%20materials/ug%20pg/pg/msc_computer_science/Advance_Software_Engineering.pdf)</sup>

该定理解决了可表达性问题，却没有解决风格问题。后来的理论工作直接考察了转换问题：1996年《计算机杂志》发表了一种形式化的、普遍适用的、从程序结构中移除所有goto语句的流程，其动机在于观察到goto语句使控制结构难以理解，并带来不终止及其他正确性问题的风险。<sup>[14](https://academic.oup.com/comjnl/article-abstract/39/3/203/399032)</sup>哈伦·米尔斯的无goto编程风格建立在关于控制流图可表达性的理论成果之上。<sup>[15](https://www.sciencedirect.com/science/article/pii/S0167642305000924)</sup>

## goto之争

在低级语言和BASIC等早期高级语言中，条件分支和循环通常用GOTO来构建，该操作指示计算机跳转到程序中完全不同的部分。在大型程序中，这些跳转以复杂的方式相互作用，使执行流程难以跟踪；此类程序被批评为“意大利面条式代码”。<sup>[16](https://openstax.org/books/introduction-computer-science/pages/4-1-models-of-computation)</sup>未能记录GOTO所造成的跳转，使商业程序变得纠缠混乱、难以维护。<sup>[4](https://www.sciencedirect.com/topics/computer-science/structured-programming)</sup>

**迪杰斯特拉的信。**艾兹格·W·迪杰斯特拉是荷兰计算机科学家，当时以在THE操作系统和并发编程方面的工作而闻名，他致信《美国计算机学会通讯》编辑，反对goto语句。这封信引发了一场关于用不用goto的争论，持续了大约二十年。<sup>[15](https://www.sciencedirect.com/science/article/pii/S0167642305000924)</sup><sup> • </sup><sup>[1](https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_and_Computation_Fundamentals/Programming_Fundamentals_%28Busbee_and_Braunschweig%29/04%3A_Conditions/4.01%3A_Structured_Programming)</sup>

**克努特的修正。**唐纳德·E·克努特是斯坦福大学计算机科学家、《计算机程序设计艺术》的作者，他于1974年12月在《美国计算机学会计算综述》6(4)：261–301发表了《使用goto语句的结构化编程》（原以斯坦福报告STAN-CS-74-416发布）。<sup>[6](https://dblp.dagstuhl.de/pid/k/DonaldEKnuth.html)</sup><sup> • </sup><sup>[17](https://cir.nii.ac.jp/crid/1971993809690801199)</sup>IBM研究部门发表了相关工作《有goto语句和无goto语句的结构化编程》，考察了多出口复合方案，这些方案无需额外变量即可描述与流程图方案相同的计算过程。<sup>[18](https://research.ibm.com/publications/structured-programming-with-and-without-go-to-statements)</sup>

## 工程实践中的结构化编程

这些思想迅速进入高可靠性软件的实践。一份1977年的美国国家航空航天局技术需求文件指出，“软件设计应遵循结构化编程的原则”，且设计与编码“应限于三种基本控制结构模式：线性顺序、选择和循环。”<sup>[19](https://ntrs.nasa.gov/api/citations/19770012122/downloads/19770012122.pdf)</sup>美国国家航空航天局现行针对任务关键型软件的编码标准指南延续了同一脉络：使用尽可能简单的流控制构造，避免“goto”和setjump/longjump；确保所有循环构造具有固定的上界并避免递归；在尽可能小的作用域内声明数据对象；在每个函数的开头验证输入参数；检查非void函数的返回值。<sup>[7](https://swehb.nasa.gov/spaces/SWEHBVD/pages/102695794/9.03%2BCoding%2BStandards)</sup>给出的理由是，一致地使用经批准的编码标准可降低常见运行时错误的频率，并提升可维护性和可复用性。<sup>[7](https://swehb.nasa.gov/spaces/SWEHBVD/pages/102695794/9.03%2BCoding%2BStandards)</sup>

结构化编程也塑造了整个领域的词汇。“软件工程”一词最初是一次由北约科学委员会资助的会议的名称，该会议于1968年在德国[加米施-帕滕基兴](https://www.edgepedia.org/zh/garmisch-partenkirchen)举行，与迪杰斯特拉的信同年。<sup>[4](https://www.sciencedirect.com/topics/computer-science/structured-programming)</sup>后来的方法论工作对结构化方法与面向对象方法进行了实证比较；一项针对任务关键型软件维护的研究发现，修改面向对象版本的一组人，比在用结构化方法和CASE工具以C语言编写的非面向对象版本上工作的同行，维护更多软件工件所需的精力更少。<sup>[20](https://www.sciencedirect.com/science/article/abs/pii/S0164121204002237)</sup>

## 遗产

结构化编程成为命令式编程的默认模式。在结构化语言中，控制流使用条件分支和迭代语句而非GOTO；例如C语言提供if和switch用于选择，提供for、while和do用于迭代，尽管该语言保留了goto关键字作为低级设施，但不建议使用。<sup>[16](https://openstax.org/books/introduction-computer-science/pages/4-1-models-of-computation)</sup>教科书的论述直截了当地总结了结果：这一概念始于20世纪60年代末迪杰斯特拉的文章，争论了约20年，到20世纪末，几乎所有计算机科学家都已确信，学习和应用结构化编程的概念是有益的。<sup>[1](https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_and_Computation_Fundamentals/Programming_Fundamentals_%28Busbee_and_Braunschweig%29/04%3A_Conditions/4.01%3A_Structured_Programming)</sup>该范式与面向对象、函数式和逻辑编程并列，是主要的编程模型之一。<sup>[8](https://www.cs.utexas.edu/~djimenez/utsa/cs2073-2/lecture6.html)</sup>

## References

1. [Structured Programming, Programming Fundamentals (Busbee and Braunschweig), Engineering LibreTexts](https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_and_Computation_Fundamentals/Programming_Fundamentals_%28Busbee_and_Braunschweig%29/04%3A_Conditions/4.01%3A_Structured_Programming)
2. [Control Flow, CS 355, Old Dominion University](https://www.cs.odu.edu/~zeil/cs355/s25/Public/controlFlow/controlFlow__slides.html)
3. [Böhm, C. and Jacopini, G. (1966). Flow diagrams, turing machines and languages with only two formation rules. Communications of the ACM 9(5), 366–371.](https://cir.nii.ac.jp/crid/1363107371315537152)
4. [Structured Programming, ScienceDirect Topics overview](https://www.sciencedirect.com/topics/computer-science/structured-programming)
5. [Dijkstra, E. W. (1968). Go to statement considered harmful [Letter to the editor]. Communications of the ACM 11(3), 147–148. Eindhoven University of Technology research portal.](https://research.tue.nl/en/publications/go-to-statement-considered-harmful-letter-to-the-editor)
6. [dblp: Donald E. Knuth, Structured Programming with go to Statements, ACM Computing Surveys 6(4): 261–301 (1974)](https://dblp.dagstuhl.de/pid/k/DonaldEKnuth.html)
7. [9.03 Coding Standards, NASA Software Engineering Handbook Ver D](https://swehb.nasa.gov/spaces/SWEHBVD/pages/102695794/9.03%2BCoding%2BStandards)
8. [Lecture 6: Structured Programming, UT San Antonio CS 2073](https://www.cs.utexas.edu/~djimenez/utsa/cs2073-2/lecture6.html)
9. [An overview of structured forms, IBM z/TPF documentation](https://www.ibm.com/docs/en/ztpf/1.1.2025?topic=introduction-overview-structured-forms)
10. [Structured Programming, Logic, Introduction to C](https://intro2c.sdds.ca/B-Computations/logic)
11. [Structured Programming, Cal Poly lecture notes (Dahlby)](https://users.csc.calpoly.edu/~jdalbey/103/Lectures/StructuredProgramming/)
12. [Böhm, C. and Jacopini, G. Flow Diagrams, Turing Machines And Languages With Only Two Formation Rules (full text scan)](https://www.cs.unibo.it/~martini/PP/bohm-jac.pdf)
13. [Advance Software Engineering, M.Sc Computer Science course material, M.S. University](https://www.msuniv.ac.in/images/distance%20education/learning%20materials/ug%20pg/pg/msc_computer_science/Advance_Software_Engineering.pdf)
14. [A Formal Basis For Removing Goto Statements, The Computer Journal 39(3), 203](https://academic.oup.com/comjnl/article-abstract/39/3/203/399032)
15. [To use or not to use the goto statement: Programming styles viewed from Hoare Logic, ScienceDirect](https://www.sciencedirect.com/science/article/pii/S0167642305000924)
16. [Models of Computation: Structured Programming, OpenStax Introduction to Computer Science](https://openstax.org/books/introduction-computer-science/pages/4-1-models-of-computation)
17. [Structured programming with GO TO statements, CiNii Research record (Stanford STAN-CS-74-416)](https://cir.nii.ac.jp/crid/1971993809690801199)
18. [Structured Programming With and Without GO TO Statements, IBM Research](https://research.ibm.com/publications/structured-programming-with-and-without-go-to-statements)
19. [NASA NTRS document 19770012122: software design shall follow structured programming principles](https://ntrs.nasa.gov/api/citations/19770012122/downloads/19770012122.pdf)
20. [An empirical investigation of the impact of the object-oriented paradigm on the maintainability of real-world mission-critical software, ScienceDirect](https://www.sciencedirect.com/science/article/abs/pii/S0164121204002237)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Programming languages › Paradigms, classification, and history

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/structured-programming

English original: https://www.edgepedia.org/structured-programming
